Display images from DataSet with single database pull

Last post 01-17-2008 1:53 PM by edwardsbr. 0 replies.

Sort Posts:

  • Display images from DataSet with single database pull

    01-17-2008, 1:53 PM
    • Loading...
    • edwardsbr
    • Joined on 01-17-2008, 1:24 PM
    • Posts 1

    Hello,

    I have been slaving away all week long trying to display images in a GridView (or a Repeater) where the image data is stored in a DataSet that was pulled from SQL Server 2005.  I am only able to display one image of the three that are in the DataSet.  I don't have the code in front of me at the moment, so I'll try to give a decent explanation of how I'm doing it.

    I call a stored procedure to get the image bits along with other fields containing text associated with the images.  I am currently using an SqlDataReader to sequentially read in the text and binary data into a DataSet that I created, because I read that that is the best way to get a BLOB from the database along with other associated fields.  One of the associated fields tells me how many bytes the image is, so I know exactly how many bytes to read using the SqlDataReader's GetBytes function.  I then take the DataSet that I just created and assign it to the DataSource of my GridView.  In my GridView I have a control that I created special for this which takes in the data (Byte[]) and just writes the data back into the stream when it is rendered.  The control always writes the header as that of a jpeg, because I am ensuring the images are always jpegs.  To get my image data into the custom control, I have a handler for the RowBinding event (I think that's what it's called), which gets the binary image data from the DataRow and gives it to the custom control.

    The main issue that I am trying to fix is that only the first image displays, even though the data is being passed into my custom image control as it should be.  One bizarre thing that I don't understand is that the data binding is being called twice when the page loads, with the second time through not binding all three images as it should.

     The theory behind my approach is simple, but I have only seen two examples on the web where people are trying to use image data that has already been retrieved from the database.  Every other example involves a seperate round-trip to get each image from the database.  I find that approach unnecessary, since I already have the data I need.  I understand that I won't get solid answers without showing code, but I'm hoping for some help to make sure the theory behind it is solid.  Is my approach reasonable?  Is there a good example out there showing what I am trying to do?  This thing is giving me some serious grief, so any input is welcome.

     Thanks for listening,
    Brent

    Brent Edwards
    SpottedFox.com
Page 1 of 1 (1 items)
Microsoft Communities
Page view counter