Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

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.

Leave a Reply