Search code examples
c#winformscrystal-reports

Why does my CR SetParameterValue seem to not work


I have a small Winforms project. .NetFramework 4.5, CR 13.0.14. In a ReportForm:

public partial class ReportForm : Form
{
    private readonly string _batchNumber;

    public ReportForm(string batchNumber)
    {
        _batchNumber = batchNumber;
        InitializeComponent();
    }

    protected override void OnLoad(EventArgs e)
    {
        APGreenSheets report = new APGreenSheets();
        DataSet data = AccountsPayableController.FillDataSet();
        report.SetDataSource(data);
        report.SetParameterValue("BatchRef", _batchNumber);
        crystalReportViewer1.ReportSource = report;
        crystalReportViewer1.RefreshReport();

        base.OnLoad(e);
    }
}

In my CR report I have a Parameter Field “BatchRef” defined as a string.

My Record Selection Formula is: {AP_HistoryHeader.strBatchRef} = {?BatchRef}

When ReportForm loads (passing in the Batch Number reference) the report still prompts me before it will load. I can type it in manually and that will work. But I have Set the Parameter after I set the DataSource to avoid that. Thanks in advance.


Solution

  • Don Williams at SAP provided me the correct answer after a few other code checks:

    Simply remove the line crystalReportViewer1.RefreshReport();

    This did the trick. Apparently the refresh part wants to renew the passed Parameter. It turns out, I didn't need it to display the report in the first place.

    Thanks to Don!