简体   繁体   中英

Passing parameter in crystal report using C#.NET

如何在Crystal报表中传递参数?

Use 'ParameterFieldInfo':

//Create report document object     
CrystalDecisions.CrystalReports.Engine.ReportDocument report =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();

ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

paramField.Name = "PARAMETER_NAME";
paramDiscreteValue.Value = "PARAMETER_VALUE";
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
//ADD MORE PARAMETERS HERE.....IF REQUIRED.

CRYSTAL_REPORT_VIEWER.ParameterFieldInfo = paramFields;
report.Load(Server.MapPath("~/Reports/CR_XYZ.rpt"));
CRYSTAL_REPORT_VIEWER.ReportSource = report;

report.SetDatabaseLogon(USER_NAME,PASSWORD,SERVER_NAME,DB_NAME);
private readonly CrystalReportViewer reportViewer = new CrystalReportViewer();
...
this.reportViewer.ReportSource = @"C:\PathToReport\Report.rpt";

using (var crystalReport = new ReportDocument())
{
...

    crystalReport.Load(this.reportViewer.ReportSource.ToString());

    crystalReport.SetParameterValue("customerId", customerId);
}

we can give a more detailed answer if the question is more detailed.

but in a nutshell, you can use ParameterField object to contain your parameter(s), add it to a ParameterFields object, and pass this to the ParameterFieldInfo property of you Crystal Report Viewer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM