I have a report that I created with Crystal Reports 2008. This report uses upwards of 40 parameters to control the layout of the report. All the parameters are boolean and are defaulted to False in the saved report. The report is saved with the save data with the report option unchecked as I want to read the results from the database rather than within the report.
However, when I go to export the report to PDF I receive a ParameterFieldCurrentValueException. I do not receive this error when the data is saved with the report.
I have verified that all five tables in the report are connected to their data source with the following code.
foreach (Table table in reportDoc.Database.Tables) { bool isConnected = table.TestConnectivity(); Console.WriteLine(table.Name + ' connected? ' + isConnected.ToString()); }
What might be causing the ParameterFieldCurrentValueException when data not saved with a report and it is exported to disk?
This is the simplest code that can reproduce this issue.
string report = 'list_report.rpt'; string pdf = 'list_report.pdf'; ReportDocument reportDoc = new ReportDocument(); reportDoc.Load(report); // Setting parameters (or not) does not have an effect on the error // All parameters have defaults // reportDoc.SetParameterValue('hideRegion', false); reportDoc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, pdf);
When you have Save Data with Report selected the report does not try to hit the database. It’s a static report with saved data. That’s why this report doesn’t error compared to when you try to pass parameters without saved data.
The error suggests that one or more of the parameter values you’re passing at runtime does not match what the report is expecting. In your code you’re exporting to PDF directly. Since you’re not viewing the report there’s no opportunity for the engine to prompt for missing values.
You can build a simple windows application that loads your report and passes it to the Crystal Report Viewer control. Start by not passing any parameter to the report without saved data. You should be prompted for all your parameters. Add them manually in the parameter prompt form. Does this work? It should. Now start adding parameter code one at a time. The parameter prompt form should just prompt for the parameters that are missing. At some point you’ll get the error again and this should help narrow down the issue.
Sincerely,
Dan Kelleher