如何更新或不更新数据库中的图像? [英] How to update or Not Update image from database ?
问题描述
图像正在更新成功但我需要当我不是更新图像..... 1时间和另一次我想更新图像..任何东西.....
< pre lang =c#> con.Open();
SqlCommand cmd = new SqlCommand( UpdateUserDetailsAug7_SP ,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue( @ UserId,ViewState [ UserId]);
cmd.Parameters.AddWithValue( @ UserName,txtUserName.Text);
cmd.Parameters.AddWithValue( @ DateOfBirth,txtDateofBirth.Text);
cmd.Parameters.AddWithValue( @ Salary,txtSalary.Text);
if (FileUploadPhoto.HasFile)
{
fileName = FileUploadPhoto.FileName;
filePath = Server.MapPath( 〜/ Images / + System.Guid.NewGuid ()+ fileName);
FileUploadPhoto.SaveAs(filePath);
fs = new FileStream(filePath,FileMode.Open,FileAccess.Read);
br = new BinaryReader(fs);
bytes = br.ReadBytes(Convert.ToInt32(fs.Length));
cmd.Parameters.AddWithValue( @ ImagePath,bytes);
}
cmd.Parameters.Add( @ Message ,SqlDbType.VarChar, 500 );
cmd.Parameters [ @ Message]。Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
string outputValue = cmd.Parameters [ @message跨度>] Value.ToString();
lblMessage.Text = outputValue;
lblMessage.ForeColor = System.Drawing.Color.RoyalBlue;
BindUserDetails();
con.Close();
< asp:TemplateField HeaderText = 照片 >
< ItemTemplate >
< asp:Image ID = img_image ImageUrl =' <%# 〜/ News / + Eval( ImagePath)% > ' runat = server 高度 = 76px 宽度 = 101px / >
< / ItemTemplate >
< HeaderStyle HorizontalAlign = Left / >
< / asp:TemplateField >
u可以查看图片网址,有一个像News这样的名字就是你的文件夹名称。当你将你的图像保存在文件夹中时,你可以在上面的代码中查找该图像。
回答问题并回答这么多次是不好的。请参阅:
http://www.codeproject.com/search.aspx?q=C#+database+%28image+OR+images+OR+bitmap+OR+bitmaps%29&doctypeid = 1; 4; 5 [ ^ ]。
- SA
Image is Updating Sucessfully But i need When i am not Update Image .....1 st Time and another time i want to update image ..any thing .....
con.Open();
SqlCommand cmd = new SqlCommand("UpdateUserDetailsAug7_SP", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", ViewState["UserId"]);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@DateOfBirth", txtDateofBirth.Text);
cmd.Parameters.AddWithValue("@Salary", txtSalary.Text);
if (FileUploadPhoto.HasFile)
{
fileName = FileUploadPhoto.FileName;
filePath = Server.MapPath("~/Images/" + System.Guid.NewGuid() + fileName);
FileUploadPhoto.SaveAs(filePath);
fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
bytes = br.ReadBytes(Convert.ToInt32(fs.Length));
cmd.Parameters.AddWithValue("@ImagePath", bytes);
}
cmd.Parameters.Add("@Message", SqlDbType.VarChar, 500);
cmd.Parameters["@Message"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
string outputValue = cmd.Parameters["@Message"].Value.ToString();
lblMessage.Text = outputValue;
lblMessage.ForeColor = System.Drawing.Color.RoyalBlue;
BindUserDetails();
con.Close();
<asp:TemplateField HeaderText="Photo"> <ItemTemplate> <asp:Image ID="img_image" ImageUrl='<%# "~/News/"+Eval("ImagePath") %>' runat="server" Height="76px" Width="101px" /> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> </asp:TemplateField>
u can check the Image url fied,there a name like News it is ur folder name. when u save ur image in folder,that image u can retrive on above code.
Its would be not good to answer the question asked and answered so many times, again and again. Please see:
http://www.codeproject.com/search.aspx?q=C#+database+%28image+OR+images+OR+bitmap+OR+bitmaps%29&doctypeid=1;4;5[^].
—SA
这篇关于如何更新或不更新数据库中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!