ASP.NET c#将参数值传递给Crystal Report

时间:2011-05-13 07:19:52

标签: c# asp.net crystal-reports parameter-passing report

喜 我是水晶报告和ASP.NET的新手 我有一个水晶报告,我想要的是通过我的asp.net页面将一个参数传递给该报告

这是我使用的代码

    protected void setParameterField()
{
    string strReportPath = "\\\\fileserver\\crude Accounting\\reports\\MonthReportNew.rpt";
    string weekReportPath = "\\\\fileserver\\crude Accounting\\reports\\" + "WeekWise.rpt";

    try
    {
        if (!System.IO.File.Exists(strReportPath))
        { throw (new Exception()); }
    }
    catch (Exception ex)
    {
        Response.Write("You Might Not Have Permission To View This Report. Please Contact System Administrator");
        Response.Write(Convert.ToString(ex.Message));
        return;
    }

    //Main Report
    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(strReportPath);
    //Sub Report - Week
    ReportDocument weekReport = new ReportDocument();
    weekReport.Load(weekReportPath);

    ParameterFields paramFields = new ParameterFields();
    ParameterField paramField = new ParameterField();
    ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
    paramField.Name = "@Document_No";
    paramDiscreteValue.Value = "BAD-0511-PRO-2";
    paramField.CurrentValues.Add(paramDiscreteValue);
    paramFields.Add(paramField);

    CrystalReportViewer1.ParameterFieldInfo = paramFields;
   cryRpt.SetParameterValue("@Document_No", "BAD-0511-PRO-2");
    cryRpt.SetDatabaseLogon("myuserid", "mypassword");        
    CrystalReportViewer1.ReportSource = cryRpt;

}

我不断收到错误参数值 我不知道这段代码有什么问题。 请帮帮我

1 个答案:

答案 0 :(得分:3)

您必须将参数传递给Crystal Report Source。像...

CrystalReportSource1.ReportDocument.SetParameterValue(0, "ParameterValue");
相关问题