Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters to report from a program

Status
Not open for further replies.

Bhuven

Programmer
Apr 16, 2007
11
ZA
I am using Crystal Reports with Visual Studio 2017. I have written a few reports and all work well in Crystal. However I need to have the parameters validated before printing and to do this I have written a program in C#. I use a button click event to fire the report and my code is as follows:

private void btnPrint_Click(object sender, RoutedEventArgs e)
{
string reportPath = @"C:\qpaq\reports\LedegerTransactionReport.rpt";
CRLedgerTransactionReport ledgerTransactionReport = new CRLedgerTransactionReport();

ledgerTransactionReport.SetParameterValue("Start Account Number", fromAccNumber);
ledgerTransactionReport.SetParameterValue("End Account Number", toAccNumber);
ledgerTransactionReport.SetParameterValue("Start Date", fromDate);
ledgerTransactionReport.SetParameterValue("End Date", toDate);

ledgerTransactionReport.Load(reportPath);

CrystalReportsViewer crystalReportsViewer = new CrystalReportsViewer();
[highlight #FCE94F] crystalReportsViewer.ViewerCore.ReportSource = ledgerTransactionReport;[/highlight]
}

1. When I run the program I get the Crystal "Enter Parameter Values" window appear but the parameters are not populated
2. When I do a trace on the code,I can see the values entered but a trace on the last line,.ReportSource, HasRecords says
" HasRecords threw an exception of type 'CrystalDecision.CrystalReports.Engine.ParameterField(CurrentValueException"
3. I cant understand why the parameters are not being passed, not sure if there is a problem with my code.
4. The parameters above are exactly as created in the Crystal report

I would like to be able run thereport from the program and not have Crystal's "Enter Parameter Values" window displayed

Please assist,
Many thanks


 


HI All,

I have been trying unsucessfully to resolve this error for the past two weeks that I get when trying to pass parameters from my C# program to Crystal reports using C# WPF viewer. I tried it also with a report that does not have parameters and the same error occurs.. My code is above

Does anyone know where I can get access to a complete program listing just to compare idf I am missing anything in my code. I have been searching on the internet for a few days for some guidance, but cannot find anything that is complete

My reports work well if I run them directly in the viewer however, I need to validate certain parameters before printing hence the need to pass the parameters via code

Any assistance will be most appreciated, Many thanks

Bhuven
 
Thank you Ian, I have as well, just thought someone may have experienced a similar problem,
Regards
 
Thank you, I resolved the problem, somewhere in my code i had instantiaited the viewer twice, the parameter were being passed to the second viewer.

Been looking at that code for two weeks before seeing the problem

Many thanks

Regards, bhuven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top