I want to retrieve an image from a SQL Server database and show in a Image
tool.
I have this code
<asp:Image ID="Image1" runat="server" CssClass="style2" Height="166px" Width="488px" />
SqlConnection connect = null;
string connectstring = "Data Source=.\\SQLEXPRESS;Initial Catalog=teste;Integrated Security=true;pooling=false";
connect = new SqlConnection(connectstring);
connect.Open();
string Scmd = "SELECT id, imagem where id = 2";
SqlCommand cmd = new SqlCommand(Scmd, connect);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
Label1.Text = reader[0].ToString();
byte[] imagem = (byte[])(reader[1]);
MemoryStream ms = new MemoryStream(imagem);
Image1.ImageUrl = ms.FromStream(ms); //i tried this
}
But I can't do this:
Image1.ImageUrl = ms.FromStream(ms);
because I get an error.
Somebody please can help me? The only problem I have is show the image.
Please help, thanks.