1

How can I put a null value on datetime variable type?

I tried to make it nullable value, but I need to use it in ReportParameter() method to send it to my report but ReportParameter() constructor cannot take a nullable value and the ReportParameter() take just a string values!

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Rashid
  • 35
  • 3
  • 8

2 Answers2

2

The various constructor overloads for ReportParameter only take in a string or string array as acceptable input.

ReportParameter Constructor

And the ReportParameter.Values property itself is actually a StringCollection in order to force the serialization to happen at compile time.

ReportParameter Properties

But you can pass a null value with string typing per this thread on Passing NULL parameter from aspx page to Report Server like this:

var rp = new ReportParameter("ServiceType_cd", new string[] { null });

Or per this question Report Viewer: Set null value to Report Parameters having allow null true, you can pass in a value like this:

string str = null;
var rp = new ReportParameter("ServiceType_cd", str));
KyleMit
  • 30,350
  • 66
  • 462
  • 664
1

you can create FailIfNull() extension method for this purpose. Please look here for more information about extension methods.

Kirill Dubovikov
  • 1,457
  • 2
  • 21
  • 41