Pass NULL value to SSRS Report from ReportViewer

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 replies on “Pass NULL value to SSRS Report from ReportViewer”

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

Leave a Reply

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