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 b开发者_如何学编程ut ReportParameter()
constructor cannot take a nullable value and the ReportParameter() take just a string values!
The various constructor overloads for ReportParameter
only take in a string or string array as acceptable input.
And the ReportParameter.Values
property itself is actually a StringCollection
in order to force the serialization to happen at compile time.
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));
you can create FailIfNull() extension method for this purpose. Please look here for more information about extension methods.
精彩评论