I am really new to this but I was learning how to store an image in a SQL Server database. All seems good, however the image as it's been stored can't be viewed in the database. I would like to know it there is a way I can store and view in the database itself?
My code stores the image correctly, but I want to be able to click on it in SQL Server and display image:
FileUpload img = (FileUpload)imgUpload;
Byte[] imgByte = null;
if (img.HasFile && img.PostedFile != null)
{
// To create a PostedFile
HttpPostedFile File = imgUpload.PostedFile;
// Create byte Array with file len
imgByte = new Byte[File.ContentLength];
// Force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength);
}
string query = "insert into dbo.sell_trans (photo ) values (@eimg)";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@eimg", imgByte);
cmd.ExecuteNonQuery();
conn.Close();
Output: