Saturday, February 25, 2012

Parameters and ReportViewer

I have a report in which I am trying to get a parameter to be displayed in a textbox. I have declared a parameter in my .rdlc called UserName and the expression in the textbox is as follows...

=Parameters!UserName.Value

With that said, I have code in the window containing my ReportViewer to set the parameters and run my report as shown below...

string UserName = "test";

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

paramList.Add(new ReportParameter(UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

With these things in mind, can anyone here provide me with a reason as to why my report on comes up with a message stating "An error occurred during local processing. One or more parameters required to run the report have not been specified." ?

If I remove the parameter and text box and strip out the code pertaining to the paramter in my window, the report runs without error.

Any ideas?

Answered my own question and it was a total noob mistake.

Assuming I have a parameter in my report named "UserName," the code in my form would need to look like the following...(I've highlighted the change in red)

string UserName = "test";

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

paramList.Add(new ReportParameter("UserName", UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

No comments:

Post a Comment