LocalReport.SetParameters 异常 尝试设置报表参数“ParameterName”;本报告中未定义的
我有两个按钮(按钮1,按钮2) 这两个按钮打开两个相同的报告,只是如果我先按下按钮1,则report2.rdlc有一个字符串参数
消息框显示参数计数= 0(如预期)并且我会在reportviewer1中显示report1.rdlc 如果然后我按下按钮2消息框再次显示参数计数= 0(我希望它显示1)并且我得到LocalProcessingException {“尝试设置一个不是报告参数'Report2ParameterString'在此报告中定义。"}
如果我先按下按钮2消息框显示参数计数= 1(如预期)并且我会在reportviewer1中显示report2 如果然后我按下按钮1消息框再次显示参数计数= 1(我希望它显示0)我会在reportviewer1中显示report1.rdlc,无一例外
我的代码是
private void report1Button_Click(object sender, EventArgs e)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report1.rdlc";
MessageBox.Show("parameters count =" + reportViewer1.LocalReport.GetParameters().Count.ToString());
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
reportViewer1.RefreshReport();
}
private void report2Button_Click(object sender, EventArgs e)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
MessageBox.Show("parameters count =" +reportViewer1.LocalReport.GetParameters().Count.ToString());
reportViewer1.LocalReport.SetParameters(new ReportParameter("Report2ParameterString", " testing Report2ParameterString"));
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
reportViewer1.RefreshReport();
}
i have two buttons (button1, button2)
the two buttons open two identical report except that report2.rdlc has a string parameter
if i pressed button1 first the message box show parameters count = 0 (as expected) and i get report1.rdlc displayed in the reportviewer1
if then i pressed button2 the message box show parameters count = 0 again (i expect it to show 1) and i get LocalProcessingException {"An attempt was made to set a report parameter 'Report2ParameterString' that is not defined in this report."}
if i pressed button2 first the message box show parameters count = 1 (as expected) and i get report2 displayed in the reportviewer1
if then i pressed button1 the message box show parameters count = 1 again(i expect it to show 0) i get report1.rdlc displayed in the reportviewer1 without exceptions
my code is
private void report1Button_Click(object sender, EventArgs e)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report1.rdlc";
MessageBox.Show("parameters count =" + reportViewer1.LocalReport.GetParameters().Count.ToString());
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
reportViewer1.RefreshReport();
}
private void report2Button_Click(object sender, EventArgs e)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
MessageBox.Show("parameters count =" +reportViewer1.LocalReport.GetParameters().Count.ToString());
reportViewer1.LocalReport.SetParameters(new ReportParameter("Report2ParameterString", " testing Report2ParameterString"));
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
reportViewer1.RefreshReport();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在加载新报表之前调用
ReportViewer.Reset()
。例如:
Call
ReportViewer.Reset()
before loading the new report.For example: