[RESOLVED] Passing Params to Crystal Reports
I'm creating a new Crystal Report. The binding is done via Dataset and it accepts params. We have existing code that applies params. These existing reports bind directly to a SPROC and they have Params that go to the SPROC and some that are just local to the report.
However, with the Dataset report, i keep getting an error "Missing parameter values" when trying to export the report to PDF.
I've tried removing ALL params and executing the report and it works just fine. Once I added a param to the report, i start seeing this error.
here is the code snippet of how the params are being set.
Code:
reportPath = reportPath + "\\" + this.Code + ".rpt";
_crystalReport.Load(reportPath, OpenReportMethod.OpenReportByTempCopy);
ParameterField paramField = new ParameterField();
ParameterDiscreteValue discreteVal;
_crystalReport.SummaryInfo.ReportTitle = this.Name;
_crystalReport.SummaryInfo.ReportComments = "";
for (int i = 0; i < _crystalReport.DataDefinition.ParameterFields.Count; i++)
{
ParameterFieldDefinition p = _crystalReport.DataDefinition.ParameterFields[i];
if (p.IsLinked())
continue;
string strValue = "";
strValue = GetReportValue(p.Name, reportParameters);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = p.Name;
if (strValue != "" || p.Name == "ColdStorageLine")
{
discreteVal.Value = strValue;
}
paramField.CurrentValues.Add(discreteVal);
_crystalReport.DataDefinition.ParameterFields[i].ApplyCurrentValues(paramField.CurrentValues);
}
Any input would be greatly appreciated.
Re: [RESOLVED] Passing Params to Crystal Reports
Apparently, you have to set the Datasource BEFORE you apply the parameters. Setting the datasource beforehand apparently clears the params.