Wednesday, March 12, 2008 9:39 AM
I'm using CR 2008. Through code we want to save report with data. What data is included with the report is determined by the report's parameters.
The report has 2 parameters defined on it. These 2 parameters are linked to the subreport, which uses a stored procedure as source. The stored procedure has the same 2 parameters as the main report. When I preview the report in the designer I'm (as expected) prompted for the 2 parameters and the reports shows the correct data, also for the subreport.
Here is the boiled down C# code that works for reports without subreports, but throws ParameterFieldCurrentValueException for reports with subreport:ReportDocument rd = new ReportDocument();
rd.Load(@"C:\Visual Studio 2005\Projects\CR\HBA InstrumentDetail.rpt"); // set parameter values:
// Save report with data to file system:
// Here I'm getting an exception:// ParameterFieldCurrentValueException was unhandled, "Missing parameter values"
rd.SaveAs(@"C:\temp\report with data.rpt", true);
If the VerifyDatabase call is omitted no data is saved with the report.
When looking at ReportDocument.DataDefinition.ParameterFields collection I can see that the report has 4 parameters in all. 2 of them is on the subreport. If I try to set them, I'm getting an exception saying something like "cannot set value for linked parameter".
I can see that many has problems with the ParameterFieldCurrentValueException exception, but not many seems to find a solution. For instance, example solution that show how to do this - this should really be made available by Crystal Report support.
Has anybody got any ideas on what to do?
Wednesday, March 12, 2008 2:44 PM
Doesn't the VerfiyDatabase call clear out the parameters? I've never seen it done this way...I'm just thinking how Verfiy Database works in the designer.
What if you exported the report in the .rpt format...
rd.ExportToDisk(ExportFormatType.CrystalReport, @"C:\temp\report with data.rpt")
then you wouldn't have to use the VerifyDatabase method.
Wednesday, March 12, 2008 9:47 PM
Thanks for your input.
VerifyDatabase does not clear out the parameters - Refresh() does that. Like I said in the original post: "If the VerifyDatabase call is omitted no data is saved with the report." - trust me I have tried it.
I just tried to call ExportToDisk instead of SaveAs - it throws the same ParameterFieldCurrentValueException "Missing Parameter values", so no luck with that.
Thursday, March 13, 2008 2:13 PM
Did you try exporttodisk without the verifydatabase call?
Friday, March 14, 2008 2:55 PM
Well, it seems to work. Without the call to VerifyDatabase data is saved with the report.
Thanks for the input.
Here is the modified code:Code Snippet
ReportDocument rd = new ReportDocument();
rd.Load(path+@"\HBA InstrumentDetail.rpt"); // set parameter values:
rd.SetParameterValue("InstrumentLogicalID", 656); // Save report with data to file system:
rd.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, path+@"\report with data (export).rpt");
Saturday, April 26, 2008 6:40 AM
I'm using CR 2008. I got the same error.ParameterFieldCurrentValueException "Missing Parameter values"
And am chane my code to the following .Now rectify.my problem
It may help for u
ParameterFieldDefinition PfDisbNo = oRpt.DataDefinition.ParameterFields["DisbNo"];ParameterValues Paraval = new ParameterValues(); ParameterDiscreteValue dcDisbNo=new ParameterDiscreteValue();
dcDisbNo.Value = nDsNo;
reportViewer.ReportSource = oRpt;
oStream = (MemoryStream)
Thanks and Regards
Monday, July 14, 2008 7:18 AMNadi
Thanks for your code worked perfectly for me, I have been searching every place for this.
Same issue had problems with Subreports and passing in Parameters.
In the first line i just replace the field name with the index no.
ParameterFieldDefinition PfDisbNo = oRpt.DataDefinition.ParameterFields;