I have some very customized reports that I designed using Microsoft Reporting rdlc files. In first report I use 43 parameters so:
R_1_1,R_1_2,R_1_3,R_1_4,R_1_5,R_1_6,R_2_1,R_2_2,…
In second report I have 78 parameters so:
R_1_1,R_1_2,R_1_3,R_1_4,R_1_5,R_1_6,R_1_7,R_1_8,R_2_1,R_2_2,…
and I use this code for bind reports:
this.ReportViewer.LocalReport.ReportPath = BaseAddress + drpReportNumber.SelectedValue.Trim() + ".rdlc";
this.ReportViewer.LocalReport.Refresh();
this.ReportViewer.LocalReport.DataSources.Clear();
Microsoft.Reporting.WebForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", new DataTable("DataSet1"));
this.ReportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.ReportViewer.LocalReport.Refresh();
if (parameters != null && parameters.Count > 0)
{
for (int i = 0; i < parameters.Count; i++)
{
ReportParameter p = new ReportParameter(parameters[i].ParameterName, parameters[i].ParameterValue);
this.ReportViewer.LocalReport.SetParameters(p);
}
}
The problem is when I create first report then I want also create the second report, report viewer raise this error:
{“An attempt was made to set a report parameter ‘R_1_7’ that is not defined in this report.”}
I have two questions;
-
Is there any limitation for parameters count?
-
I think when I bind ReportViewer to first report it does not contains
R_1_7, and in second times parameters list does not reset and it use first parameters list. How I can solve this problem?
I just found this blog post that seems to have exactly your problem.
Add this before your
this.ReportViewer.LocalReport.DataSources.Clear();: