水晶报表参数不正确C# [英] Crystal reports The parameter is incorrect C#

查看:283
本文介绍了水晶报表参数不正确C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报告有两个参数:ponumber和receiptno。我试图调用从C#页面的参数值通过URL传递的报告。当我调用报告,我得到一个错误参数不正确,但不能弄清楚为什么。我已经根据我在网上找到了各种代码更改,因为首先报告查看器说没有参数,所以这种方法似乎更好,但不工作。 / p>

我的代码:

  string ponumber = Request.QueryString [ponumber ] .ToString(); 
string receiptno = Request.QueryString [receiptno]。ToString();

//放弃报告


CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();



ParameterFields paramFields1 = new ParameterFields();
ParameterFields paramFields2 = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterDiscreteValueparamDiscreteValue1 = 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(); //< - 此行添加
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();


解决方案

我发现了另一个答案,驼峰。我替换了13行代码:

  CrystalReportSource1.ReportDocument.SetParameterValue(0,ponumber); 
CrystalReportSource1.ReportDocument.SetParameterValue(1,receiptno);

将值传递给Crystal报表



不是手动构建集合,而是源代码具有不同的方法以设置参数值。我怀疑我的第一次尝试是即时创建参数。


I have a report that has two parameters: ponumber and receiptno. I'm trying to call the report from a C# page where the parameter values are passed in via the URL. When I call the report, I get an error "The parameter is incorrect", but can't figure out why. I've done a variety of code changes based on what I found online, because at first the Report Viewer said there were no parameters, so this approach seems to be better, but doesn't work.

My code:

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();

解决方案

I found another answer on SO that got me over the hump. I replaced 13 lines of code with:

CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);

Passing Values to a Crystal Report

Rather than build the collection manually, it looks like the source has a different method to setting parameter values. I suspect my first attempt was to create parameters on the fly.

这篇关于水晶报表参数不正确C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆