Rdlc how to show image from database

rdlcreporting-services

I have a collection which contain images. I want to show those images on my RDLC report. Can anyone show me how to do that?

Please give me code or example.

Best Answer

If you want to retrieve an image from a table in a database and use it in a Reporting Services report all you have to do is create a data source that contains a field with the image and use it as data source of the image field, like you do with the rest of the data you show on the report.

Imagine you have a table named image_table with a column named image_col.

All you have to do is create a data source with a select sentence like:

SELECT image_col FROM image_table WHERE your_condition_here

Once you have the data source you assign it to the image field DataSource property and assign the Fields!image_col to the Value property of the image field. With this you have the image on the report.

To test the idea you can follow this steps:

1) Define a strong typed DataSet with a table name "image_table"

2) The image_table will have 2 columns IdCol (a numeric column) and image_col a (Byte() column)

3) Fill a dataset with data using something like this:

    Dim cText As String
    Dim myDataSet As dsImageDataset

    cText = "SELECT idCol, image_col FROM image_table"
    Dim sCommand As New SqlClient.SqlCommand(cText, yourConnection)
    Dim dAdapt As New SqlClient.SqlDataAdapter(sCommand)
    dAdapt.Fill(myDataSet, "image_table")

This will fill the dataset myDataSet with all the images in the table image_table.