Running on ASP.NET 2.0 and SQL Server 2005. Have a table with an image-type column to store a photo. I have already created the script to upload/store the file in the DB, but I need code to handle the output.

I already have a stored proc call the retrieves the data based on an id... the recordset retrieved is one row with the photo and a few other text fields.

Please advise the necessary code to place in the codebehind file to display this photo. I am using <asp:label> tag for the positioning of the image.

Thanks!

-------------------------------------------
Re: Displaying image from database...

here are some code bits I have used in the past to get binary data from sql server, but I only know how to response write the data as the full output for a page and then reference it in the html, I would try a searching on google for actually binding binary image data to the page (not sure if it can be done), I seroiusly doubt that you will be able to bind to an asp:label

here is how I have done this in the past
html in an aspx page where you want to show an image from the database
<img src="GetImage.aspx?id=39" />

then you create a GetImage.aspx page that responses gif or jpg data

// get data from db
fileTitle = rs["FileTitle"].ToString();
fileSize = rs["FileSize"].ToString();
contentType = rs["ContentType"].ToString();
byte[] fileData = (byte[]) rs["FileData"];

// response output
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.Buffer = false;
Response.ContentType = contentType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileTitle);
Response.AddHeader("Content-Length", fileSize.ToString());
Response.BinaryWrite(fileData);

------------------------------------

相关文章:

  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-10-20
  • 2021-05-29
  • 2022-12-23
  • 2021-05-19
猜你喜欢
  • 2021-10-23
  • 2021-07-19
  • 2021-07-21
  • 2022-02-09
  • 2022-03-05
  • 2021-08-21
  • 2021-12-27
相关资源
相似解决方案