• Home
  • About
  • Resume

Pass NULL value to SSRS Report from ReportViewer

By , 09/27/2011 4:37 PM

When working with ReportViewer ASP.NET control to display SSRS report on an ASPX page you can use ReportParameter class to create and pass parameters to the server, e.g.

aParamList.Add(New ReportParameter("MyParam", sValue, False))

Here aParamList is a Generic List of ReportParameter objects that you use in ReportViewer’s ServerReport.SetParameters method, "MyParam" is a parameter name and sValue is a string variable with value for the parameter. Third parameter – visibility, when set to False makes the parameter hidden.

All is well, but what if you need to pass NULL parameter? Unfortunately ReportParameter‘s constructor accepts only string type for it’s value parameter, so you cannot pass something like DBNull.Value or Nothing. Fortunately there’s an easy solution: Just set you string variable representing value to Nothing:

sValue = Nothing
aParamList.Add(New ReportParameter("MyParam", sValue, False))

Voila! Desired NULL is passed as a parameter value (on SSRS side parameter has to be set to accept NULL values).

Thanks Tincy for the original idea.

2 Responses to “Pass NULL value to SSRS Report from ReportViewer”

  1. Prosper says:

    Doesn’t seem to work for me.

  2. Yuriy says:

    @Prosper: Are you getting any error messages? Can you trace what parameter is being passed to underlying query/sp?

Leave a Reply

Panorama Theme by Themocracy