Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How do I set a report's parameter with values when using SetDataSource?

I am getting the following error when trying to load a report:

This field name is not known.

Details: errorKind Error in File MyReport.rpt {7A17AD68-F569-45A8-9655-0BDB71FCA28A}.rpt:

Error in formula Section_Visibility:

'{?P_ETHNICITY} <> 'G01' '

This field name is not known.

Details: errorKind

This report uses an Oracle database as its data source. Parameters are passed in at run time and the report engine connects to the database to retrieve its data. The report has an expression

{?P_ETHNICITY} <> 'G01'

for the Suppress property of one of its footer sections (where P_ETHNICITY is one of the parameters).

The report is used in a legacy VB6 system which I am rewriting in C# and using Crystal Reports for VS2010 (SP 1 (v13.0.1)). For reasons unrelated to this thread, I do not want the report to retrieve its own data as it once did. Rather, I want the C# code to retrieve the data in a DataTable and pass it to the report. This works well for other reports when I use the following code:

private void LoadReportData(
    CrystalDecisions.CrystalReports.Engine.ReportDocument reportDoc, 
    string reportFilePath, 
    System.Data.DataTable reportData)
{
    reportDoc.Load(reportFilePath, OpenReportMethod.OpenReportByDefault);
    reportDoc.Database.Tables[0].SetDataSource(reportData);
}

But for this report (and several others) it fails with the error above. I have attempted (unsuccessfully) to set the report's parameters with values by modifying the code to the following:

private void LoadReportData(
    CrystalDecisions.CrystalReports.Engine.ReportDocument reportDoc,
    string reportFilePath,
    System.Data.DataTable reportData,
    string[] reportParameterValues)
{
    reportDoc.Load(reportFilePath, OpenReportMethod.OpenReportByDefault);
 
    // Start at index 1 because the first parameter in the stored proc is the
    // ref cursor and the reportParameterValues array contains only values
    // for the other parameters.
    for (int index = 1; index < reportDoc.ParameterFields.Count; index++)
    {
        reportDoc.SetParameterValue(index, reportParameterValues[index - 1]);
    }
    
    reportDoc.Database.Tables[0].SetDataSource(reportData);
}

I have also tried calling SetDataSource before the loop that calls SetParameterValue but it makes no difference.

The stored proc that the report once used to retrieve data (and also the proc that the C# uses to retrieve the DataTable) has a signature of:

procedure rpt_ethnicity_proc (
    ethnicity     in out    rpt_generic_pkg.rpt_generic_cur,
    p_area        in        varchar2,
    p_location    in        varchar2,
    p_gender      in        varchar2,
    p_ethnicity   in        varchar2)

The first parameter is the cursor for the resulting data but the reportParameterValues array passed to the LoadReportData method only has values for the remaining parameters. This is why the index variable starts at 1 and why the reportParameterValues argument is referenced by index - 1.

What am I doing wrong? Is it even possible to use such a report in this way? I have searched everywhere but cannot find anyone with the same problem.

Former Member
Not what you were looking for? View more on this topic or Ask a question