Reputation: 81
I am getting a persistent error when I attempt to set RDLC report parameters. The parameter is defined in the report, and I get this error when I try to programatically set the parameter. An attempt was made to set a report parameter 'ReportParameter1' that is not defined in this report
The code I am using is:
ReportParameter p1 = new ReportParameter("ReportParameter1", Payments);
rep.SetParameters(new ReportParameter[] { p1 });
rep.Refresh();
Upvotes: 1
Views: 5143
Reputation: 6499
if you change path of report dynamic, remember reset it before change
reportViewer1.Reset();
Upvotes: 2
Reputation: 21
I had the same problem while using vs 2010 Professional. But I managed to find the answer to that problem. It's simple vs checks to which report to assign the parameter and finds none so it throws the error. what you need to do is to load the report and then set the parameters.
Use the order as follows;
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("parameterName1", Parameter1Value));
parameters.Add(new ReportParameter("parameterName2", Parameter2Value));
// Specify the report to load
ReportViewer1.LocalReport.ReportPath = YourReportPath;
// Set parameters to the specified report
ReportViewer1.LocalReport.SetParameters(parameters);
// Load the report
this.ReportViewer1.RefreshReport();
Upvotes: 0
Reputation: 2160
You can try with this code.I have used this code for my report
// Add Parameter if you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("parameterName1", Parameter1Value));
parameters.Add(new ReportParameter("parameterName2", Parameter2Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
Parameter name should be same with report parameter,i think you already know that.
Upvotes: 0