我有一个包含两个参数的报告:ponumber 和receiptno。我正在尝试从通过 URL 传入参数值的 C# 页面调用报告。当我调用报告时,我收到一个错误“参数不正确”,但无法弄清楚原因。我根据网上查到的,做了各种代码修改,因为一开始Report Viewer说没有参数,所以这个方法好像更好,但是不行。
我的代码:
string ponumber = Request.QueryString["ponumber"].ToString();
string receiptno = Request.QueryString["receiptno"].ToString();
// Put Away Report
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
ParameterFields paramFields1 = new ParameterFields();
ParameterFields paramFields2 = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();
paramField1.Name = "@ponumber";
paramDiscreteValue1.Value = ponumber;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramField1.HasCurrentValue = true;
paramFields1.Add(paramField1);
paramField2.Name = "@receiptno";
paramDiscreteValue2 = new ParameterDiscreteValue(); // <-- This line is added
paramDiscreteValue2.Value = receiptno;
paramField2.CurrentValues.Add(paramDiscreteValue2);
paramField2.HasCurrentValue = true;
paramFields2.Add(paramField2);
CrystalReportViewer1.ParameterFieldInfo = paramFields1;
CrystalReportViewer1.ParameterFieldInfo = paramFields2;
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];
TableLogOnInfos infos = new TableLogOnInfos();
infos.Add(logOnInfo);
CrystalReportViewer1.LogOnInfo = infos;
maindiv.Controls.Add(CrystalReportSource1);
maindiv.Controls.Add(CrystalReportViewer1);
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
CrystalReportViewer1.DataBind();