views:

1367

answers:

4

I have discovered that in SQL Reporting there might be a problem. I have a ReportViewer on my page and I am sending in parameters using the following method:

List<ReportParameter> myParams = new List<ReportParameter>();

myParams.Add(new ReportParameter("Start_Date", StartDate));
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);

This works great! But, when I try to set a parameter to null, after running that query, it maintains the previous value rather than setting it to null.

I run this code on another event that executes after the above code:

List<ReportParameter> myParams = new List<ReportParameter>();

myParams.Add(new ReportParameter("Start_Date")); 
// I even tried omiting this line.  
//(This is the null parameter I wish to pass)
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);

Has anyone come across a work around or a different technique to get this working?

Also if I initially do not define the parameter, then assign the parameter, then do not define the paramter, it maintains the value that was assigned. (These are all postbacks, each event)

A: 

What happens if you pass an empty String?

Andrew Hare
It sets the value to nothing.. but not null.
A: 

Are those StartDate & EndDate variables of type DateTime? Maybe this has to do with the fact that DateTime variables cannot be set to null, they are DateTime.MinValue instead. Try setting the parameter to DateTime.MinValue and handle accordingly.

mccrager
No they are strings and not dates actually.
+2  A: 

Do something like this..I've tested it in my own little test project and it seems to work.

List<ReportParameter> myParams = new List<ReportParameter>();

ReportParameter p = new ReportParameter("Start_Date");
p.Values.Add(null);
myParams.Add(p);

//myParams.Add(new ReportParameter("Start_Date")); 
// I even tried omiting this line.  
//(This is the null parameter I wish to pass)
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);
Mozy
It is set to allow null.
If I initially do not define the parameter, then assign the parameter, then do not define the paramter, it maintains the value that was assigned. (These are all postbacks, each event)
+1  A: 

Have you tried calling:

ReportViewer1.Reset();

in between the two calls?

J.13.L