cdonner
cdonner

Reputation: 37658

RDLC + ReportViewer Control - how to display images from the database?

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.

Upvotes: 1

Views: 5947

Answers (2)

cdonner
cdonner

Reputation: 37658

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);
        }
    }

Upvotes: 2

Kevin Buchan
Kevin Buchan

Reputation: 2860

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.

Upvotes: 1

Related Questions