LocalReport.SetParameters异常试图设置未在本报告中定义的报表参数'参数名称' [英] LocalReport.SetParameters Exception An attempt was made to set a report parameter 'ParameterName' that is not defined in this report
问题描述
我有两个按钮(按钮1,按钮2)
除了report2.rdlc两个按钮开两个相同的报告有一个字符串参数
如果我按下BUTTON1第一个消息框显示参数计数= 0(预期),我得到report1.rdlc显示在reportviewer1
如果当时我按下按钮2 消息框显示的参数计算= 0再次(我希望它显示1),我也得到LocalProcessingException {试图设置未在本报告中定义的报表参数'Report2ParameterString'。}
如果我第一次按下按钮2 消息框显示参数计数= 1(预期),我得到报告2显示在reportviewer1
如果当时我按下按钮1 <强>消息框显示参数计数= 1再次(我希望它显示0)我得到report1.rdlc显示在reportviewer1没有例外
我的代码是
私人无效report1Button_Click(对象发件人,EventArgs五)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath +\\report1.rdlc
MessageBox.Show(参数数=+ reportViewer1.LocalReport.GetParameters()Count.ToString());
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(新ReportDataSource(数据集1,reportDataTable));
reportViewer1.RefreshReport();
}
私人无效report2Button_Click(对象发件人,EventArgs五)
{
reportViewer1.LocalReport.ReportPath = Application.StartupPath +\\report2.rdlc
MessageBox.Show(参数数=+ reportViewer1.LocalReport.GetParameters()Count.ToString());
reportViewer1.LocalReport.SetParameters(新ReportParameter(Report2ParameterString,测试Report2ParameterString));
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(新ReportDataSource(数据集1,reportDataTable));
reportViewer1.RefreshReport();
}
呼叫 ReportViewer.Reset()
加载新的报告之前
例如:
reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = Application.StartupPath +\\report2.rdlc
...
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();
}
Call ReportViewer.Reset()
before loading the new report.
For example:
reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
...
这篇关于LocalReport.SetParameters异常试图设置未在本报告中定义的报表参数'参数名称'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!