SQL Server Reporting Services (SSRS) – How to Receive an Image into a Report Parameter to a SSRS Report

In this example, I will demonstrate how to convert an image in an Windows Form Application to a Base64 String that can be used to populate a report parameter that will be received into a SQL Server Reporting Services report as a report parameter.

For example, in my Windows Forms Application, I take an image that is already stored in an image variable called mImage, and convert it to a base64string with the following code:

Private mSignatureString As String = String.Empty
mSignatureString = ImageToBase64(mImage , System.Drawing.Imaging.ImageFormat.Jpeg
Public Function ImageToBase64(ByVal mImage As Image, ByVal format As System.Drawing.Imaging.ImageFormat) As String
     Using ms As New MemoryStream()
         ' Convert Image to byte[]
         mImage.Save(ms, format)
         Dim imageBytes As Byte() = ms.ToArray()
         ' Convert byte[] to Base64 String
         Dim base64String As String = Convert.ToBase64String(imageBytes)
         Return base64String
     End Using
End Function

I then pass the variable mSignatureString as a parameter called ‘Signature‘ to the process that calls my SSRS report.

My code to that looks like this:

Dim myparams As New List(Of ReportParameter)

Dim myparam As New ReportParameter("some_guid", mSomeObject.some_guid.ToString)
 myparams.Add(myparam)

Dim myparam1 As New ReportParameter("Signature", mSignatureString)
 myparams.Add(myparam1)
 
 Dim mNewReport As New frmReportViewer(e.ClickedItem.Text, e.ClickedItem.Tag, True, False, myparams)

NOTE: I don’t cover the reportviewer control that is placed on a windows form and the code behind in this post.

NOTE: If no signature is required on the report, just pass something like ‘NOSIG‘ into the parameter instead so the report can make the image control invisible so not to produce the ‘red X’ box. You will see how I use the text value of ‘NOSIG‘ when building the report below.

Building the Report

Define a parmater in SSRS and call it Signature

 

Add an Image control to the report.

Open up the Image Properties. Set the ‘image source’ = “Database” and MIME type¬†= “image/bmp”.

 

In Image Properties, click the ‘Fx’ button under “Use this field:” and type the following expression:

In Image Properties, click ‘Visibility’. Click radio button ‘Show or hide based on an expression’ and enter the following:

If the parameter value passed from visual basic = “NOSIG“, then nothing will appear in the signature line else the image will appear.

4 thoughts on “SQL Server Reporting Services (SSRS) – How to Receive an Image into a Report Parameter to a SSRS Report”

    1. Hello

      Where did you place the passing of parameters in SSRS, visual studio? I have place the function in the code area of the report properties but I am not sure about the passing of the parameters:

      Private mSignatureString As String = String.Empty
      mSignatureString = ImageToBase64(mImage , System.Drawing.Imaging.ImageFormat.Jpeg

  1. Sorry for the confusion. The logic that “you” put in the report properties code behind doesn’t belong in the report at all. All of it goes in the application you are using to build the parameter and call the report.

    The only thing that is needed in the report begins with title: “Define a parameter in SSRS and call it Signature”.

    I apologize that I didn’t make that clear. The title of post should say, “How to RECEIVE an image into a report parameter to a SSRS report. I will update the post.

    In the logic prior to calling the function (I use a function for reusability, but it is not necessary), my signature image is already sitting in a variable called mImage as seen below …. ImageToBase64(mImage …..

    Private mSignatureString As String = String.Empty
    mSignatureString = ImageToBase64(mImage , System.Drawing.Imaging.ImageFormat.Jpeg

    Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *