Dela via


How to: Add a Data-Bound Image (Reporting Services)

A report definition can include a reference to an image that is stored in a database. Such an image is known as a data-bound image. Add a data-bound image to the report body by dragging the Image report item from the Toolbox to the design surface, as you would for any report item. Adding a data-bound image to a page header or page footer requires additional steps. For more information, see Adding Page Headers and Footers.

If you created or stored the image in Microsoft Access, the image includes OLE header information that prevents the image from displaying on the report page at run time. You can remove the OLE header by using the second procedure below.

To add a data-bound image

  1. In Design view, click Image in the Toolbox.

  2. On the design surface, click the design surface and then drag the mouse to create a box that is the size of the desired image. Alternatively, click the design surface to create an image item of fixed size.

  3. In the Image Properties dialog box type a name in the Name text box, or accept the default.

  4. (Optional) In the Tooltip text box, type text to display when the user hovers the mouse over the image in the rendered report.

  5. In Select the image source, select Database.

  6. In Use this Field, select the field that contains the image.

  7. In Use this MIME type, select the MIME type of the image.

  8. Click OK.

    An image placeholder appears on the report design surface.

To remove the OLE header from an Access image

  1. Add an image from an Access data source as described in the previous procedure.

  2. In the Image Properties dialog box, click the expression (fx) button.

  3. In the Expression dialog box, copy the following expression, with no line breaks, into the expression pane:

    =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!ImageFieldName.Value),105))

    The expression uses Mid to exclude the header information, which resides in the first 105 characters of the file, and then uses Convert to make the rest of the image base64 encoded. The expression assumes that the image originates in an EN-US database. If you are using a different collation, the OLE header might be longer or shorter than 105 characters.

  4. Click OK twice.

    An image placeholder appears on the report design surface.