LocalReport.SetParameters 异常 尝试设置报表参数“ParameterName”;本报告中未定义的

发布于 2025-01-06 08:30:18 字数 1556 浏览 1 评论 0原文

我有两个按钮(按钮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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2025-01-13 08:30:18

在加载新报表之前调用 ReportViewer.Reset()

例如:

reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
...

Call ReportViewer.Reset() before loading the new report.

For example:

reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文