Hello
i am trying to retrieve images from database.But my code is not working.Please help me.Thanks
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=company;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select image from image", conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()) //yup we found our image
{
Response.ContentType = dr["Image"].ToString();
Response.BinaryWrite((byte[])dr["Image"]);
Response.Write(System.Environment.NewLine);
}
Response.Close();
conn.Close();
Muhammad imranPosted May 23, 2013, 1:48 AM
Parveen SiwachPosted May 16, 2013, 6:28 AM
I am explaining with ListView:
runat="server" />
runat="server" />
In this control: "picAlbum" image control will show all the images based on "Pic_Id" from database.
You have to create an Handler(ashx file) e.g.: ShowImage.ashx to render the image based on Pic_Id.
Muhammad imranPosted May 16, 2013, 6:07 AM
Shankar MPosted May 16, 2013, 4:54 AM
The ExecuteScalar() Method here ,
byte[] image = (byte[])command.ExecuteScalar();
just takes only the first column first row of the result set. And here we are converting it to byte[] array type.
Thanks, Shankar M
Muhammad imranPosted May 16, 2013, 4:14 AM
Parveen SiwachPosted May 16, 2013, 2:26 AM
you can follow this link:
http://www.codeproject.com/Articles/268123/Display-Store-and-Retrieve-Image-Data-from-Databas
This can help you to solve your problem.
Shankar MPosted May 16, 2013, 2:10 AM
I tried it, Its working Fine my dear friend, try this..
Code :
Thanks, Shankar M
Muhammad imranPosted May 16, 2013, 1:32 AM
Shankar MPosted May 16, 2013, 12:12 AM
Please try this link,
http://net-informations.com/csprj/dataset/cs-insert-image.htm
http://net-informations.com/csprj/dataset/cs-retrieve-image.htm
Thanks, Shankar M
Jignesh TrivediPosted May 15, 2013, 11:54 PM
hi,
I think you must convert your image byte to memory stream object and write with in image object.
please refer
http://www.codeproject.com/Articles/354639/Storing-and-Retrieving-Images-from-SQL-Server-Usin
http://mitch-wheat.blogspot.in/2007/05/save-and-restore-filesimages-to-sql.html
hope this will help you.