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
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