hai,
i want to retrieve image from sql table which is stored in the format of binary data with image. I just want to display the image in my web page thats all.. im not using with data grid also...
Thanks,
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Feb 9, 2011, 1:32 PM
if ( rdr.Read()) {byte[] bytePhoto = File.ReadAllBytes(rdr["photo"]);
Response.OutputStream.Write(bytePhoto, 0, bytePhoto.Length);
//Response.ContentType = "image/jpg";
}
Raju KatarePosted Feb 9, 2011, 5:08 AM
First you asked that how to display image which is stored in a sql table in the format of Binary Data, then you can get solution to this problem using Handler.ashx Template of ASP.Net (which is there in above article.)
krithika muthukrishnanPosted Feb 9, 2011, 4:56 AM
hai,
i didn't get the solution,i use this code,it displays the file path of the image,using that file path how to display in a c# file
SqlConnection con = new SqlConnection(@"data source=System-7\sqlExpress;initial catalog=Forum; User ID=sa;Password=as;");
con.Open();
int i = 1;
string query = "select photo from members where userid='"+i+"'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader rdr = null;
rdr=cmd.ExecuteReader();
if ( rdr.Read()) //yup we found our image
{ Response.BinaryWrite((byte[])rdr["photo"]); }
con.Close();
Raju KatarePosted Feb 9, 2011, 1:37 AM
Raju KatarePosted Feb 8, 2011, 4:32 AM
Have a look at Handler class of
GridView nested inside another GridView in ASP.NET
article to retrieve the image from database table column of type Varbinary(max). .