Reputation:
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)
Upvotes: 6
Views: 5469
Reputation: 7491
Have you tried calling:
ReportViewer1.Reset();
in between the two calls?
Upvotes: 3
Reputation: 1336
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);
Upvotes: 8
Reputation: 1038
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.
Upvotes: 0