ASP.NET with C# and SQL SERVER , some vb.net . asp.net examples, asp.net codes, asp.net programs, c# code, sql server queries, important codes.
Tuesday, 16 October 2012
Save image in Database and display it on Asp.Net C#
save
--------------------------------
SqlCommand cmd = new SqlCommand("insert into product1 values(@product,@image)", cn);
cmd.Parameters.AddWithValue("@product", TextBox1.Text);
int imagelen = FileUpload1.PostedFile.ContentLength;
byte[] picbyte = new byte[imagelen];
FileUpload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);
cmd.Parameters.AddWithValue("@image", picbyte);
cmd.ExecuteNonQuery();
cn.Close();
--------------------------------------
display
------------------------
cn.Open();
SqlCommand cmd = new SqlCommand("select * from product1 where product=@product", cn);
cmd.Parameters.AddWithValue("@product", product);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
Byte[] data = (Byte[])dr["image"];
Response.BinaryWrite(data);
Response.Write("aa");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment