I'm learning how to pass parameters to a Crystal Report from a C# asp.net webform. I've found one way to pass parameters, but its 6 lines of code per parameter. Can anyone suggest a simpler way to pass parameters (both discrete and range) to the report?
Asked
Active
Viewed 5,737 times
0
-
What's the code you're using? – Ian Jacobs Jan 14 '11 at 18:53
-
Standard, such as can be found lots of places online, including http://imar.spaanjaars.com/310/passing-multiple-parameters-to-a-crystal-report-programmatically – MAW74656 Jan 14 '11 at 18:55
2 Answers
1
Here's a question and answer I had that addresses this question:
Out of the code that I posted in the answer, here's what I think is relevant to your problem:
private readonly CrystalReportViewer reportViewer = new CrystalReportViewer();
...
crystalReport.Load(this.reportViewer.ReportSource.ToString());
crystalReport.SetParameterValue("customerId", customerId);
crystalReport.SetParameterValue("isCurrent", isCurrent);
crystalReport.SetParameterValue("TotalSales", totalSales);
Good luck!

Community
- 1
- 1

Chris B. Behrens
- 6,255
- 8
- 45
- 71
-
@Chris B. Behrens: I think you've answered a question which is much more advanced than, and unrelated to, mine. I just want a good way to pass paramters to a report. 6 lines a piece seems like a nightmere, but I can't think of a way to abstract those lines. – MAW74656 Jan 14 '11 at 18:48
-
I've updated the answer to be a little more direct. Hope this helps. – Chris B. Behrens Jan 14 '11 at 18:50
-
Your saying that I can load the report, then use the simple method SetParamterValue("", "") to add the parameters quickly? Do I have to do anything after that, like assign the report back to to the reportviewer's source? – MAW74656 Jan 14 '11 at 18:54
-
At that point, you've got an in-memory rendering of the Crystal Report. If you want to write it to disk, you would use the ExportToDisk function. This example exports to PDF: `crystalReport.ExportToDisk(ExportFormatType.PortableDocFormat, outputPath);` – Chris B. Behrens Jan 14 '11 at 18:57
-
I want to then display it in the crystal report viewer on my asp.net webform. – MAW74656 Jan 14 '11 at 18:58
-
I haven't done that. I'd give this stuff a try, and maybe look for a Refresh method on the viewer? Something like that. – Chris B. Behrens Jan 14 '11 at 19:01
-
Ok, I will. Do you know what namespace that Report object is in? I can seem to find it. – MAW74656 Jan 14 '11 at 19:03
-
Here are the namespaces I've got in the header: using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using CrystalDecisions.Windows.Forms; I am referencing these two libraries in my proj file: CrystalDecisions.CrystalReports.Design CrystalDecisions.CrystalReports.Engine CrystalDecisions.Data.AdoDotNetInterop CrystalDecisions.Shared CrystalDecisions.Windows.Forms – Chris B. Behrens Jan 14 '11 at 19:13
-
Found it, CrystalDecisions.CrystalReports.Engine. I wasn't going deep enough. How can I pass range values using this method? – MAW74656 Jan 14 '11 at 19:17
-
1I haven't used range parameters, so I'm not sure...maybe break up the range into two discrete parameters? – Chris B. Behrens Jan 14 '11 at 19:22
-
-
Works great for ranger parameters too, just send 2 discrete parameters and then in the Crystal Report select expert, use both of them (where date is between fromdate and todate). – MAW74656 Jan 26 '11 at 17:52
1
You might want to have a look at http://www.fetal.de/en/crystal-reports-ohne-den-enter-parameter-values-dialog

Izmoto
- 1,939
- 2
- 17
- 21