views:

825

answers:

2

I am storing GIF images (I can switch to BMP if necessary) in a varbinary column in SQL 2008. I want to display these images in a PDF rendered by the ReportViewer control from my RDLC. How do I have to reference the image data in the report to make that work?

=First(Fields!sh_lot_num_barcode_image.Value, "DataSet1"))

A simple field reference does not seem to do the trick.

+1  A: 

Have you considered writing an HTTP Handler to read the image from the database and write it to the response stream? Then you can set the image control in your report to use the URL as the source and it should render in the output.

I don't have any actual images as blobs in a database to test with, but I did something sorta similar when I needed to render rich text on a report.

Kevin Buchan
I do have an HTTP handler that serves the barcodes, but can I dynamically compose the URL in the image control? I would very much prefer that, but it looked to me like this is not an option. Documentation on this is very sparse ...
cdonner
Can you compose the URL in your SQL query and just reference that column as the http source? That's what I did.
Kevin Buchan
A: 

So it turns out my question was already asked before and self-answered. Give Tina your vote!

Together with Kevin's answer it got me on the right trail. I ended up adding a property to my Linq stored procedure results class that invokes the image HTML Handler. I changed the MIME type to BMP and it works like a charm - I can drop the database column now and don't need to jump through hoops to compose the URL for the image service. This property below I can directly assign to the image control.

public byte[] NDCLabel {
    get {
        return 
            BarcodeUtilities.ConvertImageToByteArray(
                BarcodeUtilities.GetBarcodeImage(this.ndc) 
                       ,System.Drawing.Imaging.ImageFormat.Bmp);
        }
    }
cdonner