Binding to images stored in database...

  • Thread starter Thread starter Charlie
  • Start date Start date
C

Charlie

Hi:

When storing images (.gif, .jpg) in binary fields in SQL Server, how do I
bind them to asp.net image control without first writing them to a file and
attaching to URL property? For example, if I'm using a DataList that's
binds to a table in a database, and one column of table is an image field
containing a graphic, how do I bind it to an image control that is contained
in DataList template.

Thanks,
Charlie
 
Charlie, what you might want to consider is to change the url on the image
control to point to something like this "streamimage.aspx?recordid=1" where
recordid=1 could be a databinding evaluation to the unique id for the record.

Then, create a streamimage.aspx file that queries the database and retrieves
the binary data for the image, then use the Response.WriteFile(stream) method
to write the image to the output stream for the streamimage.aspx. This will
result in the behavior you desire...
 
Back
Top