Reputation: 1
How to pass the parameter in Crystal report?
Upvotes: 0
Views: 2486
Reputation: 2905
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);
Upvotes: 1
Reputation: 6297
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);
}
Upvotes: 1
Reputation: 729
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.
Upvotes: 0