简体   繁体   中英

Setting/Passing a Value to a Parameter to a Crystal Report in c# is Not Working

I have 2 parameters (Detail, Summary) that I have created in a Crystal Report. The report is called from c# in a Windows Forms application. I am trying to pass the appropriate value to each parameter at runtime so the report can make some decisions based on the values. I have read many articles regarding this and I think I am using the best method to accomplish this?

This is the simple code I have implemented after the report has been loaded and before the SetDataSoruce has been set:

crReportDocument.SetParameterValue("DetailView", false);
crReportDocument.SetParameterValue("SummaryView", true);

For some reason the values are not getting to the report as the report is always prompting for the values to be set when it runs.

Everything else about the report works correctly.

I would appreciate any light someone can shed on this matter as it seems to be a simple task to do?

The problem is that the parameter must be passed using format {?PARAMETER} . It works.

crReportDocument.SetParameterValue("{?DetailView}", false);

crReportDocument.SetParameterValue("{?SummaryView}", true);

Actually the problem was code placement. I was populating the parameters in the wrong place of code execution:

This is how I had it when it was not working:

crReportDocument.SetParameterValue("FromDate", dtmFromDate);
ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;

To resolve I moved the code around as follows:

ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;
crReportDocument.SetParameterValue("FromDate", dtmFromDate);

That's all it took to get it to work correctly. Let me know if it does not work for you.

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