Friday, February 24, 2012

How to set a ReportParameter to the value NULL?

Hi,

how can I set a ReportParameter in C# to NULL? My code is as follows

ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("LanguageID", "1");
param[1] = new ReportParameter("TopCount", "30");
this.ReportViewer1.ServerReport.SetParameters(param);

Sometimes I want to pass the value NULL for the parameter TopCount so my stored proc can handle a special case. I tried

param[1] = new ReportParameter("TopCount", null);

but it doesn't work...

I know, that there is a possibility for using urls to pass parms. There you have to put the parm name, followed by ":isnull=true".

Thanks,
Dirk

You didn't say exactly how it's not working, but I'm guessing that you're getting a compilation error because the second argument to the ReportParameter constructor is ambiguos.

Try this:

string val = null;
param[1] = new ReportParameter("TopCount", val);

|||Thanks, Chris, thats it!

No comments:

Post a Comment