65.9K
CodeProject is changing. Read more.
Home

Passing Parameters to Crystal Reports at Runtime

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.91/5 (27 votes)

Nov 21, 2003

CPOL
viewsIcon

157440

downloadIcon

3617

Get and set the parameter value from the report

Introduction

This article describes how to get and set the parameter value from the report:

Crystal_net_parameters.jpg

Example

This example is composed of:

  1. A sample report 

  2. A form that loads the report automatically and shows the preview report

  3. A button that retrieves the parameter's actual value using the method:

    private string GetParamValue (string paramName)
    {
        string tmpValue="";
        for(int i=0;i<ReportDoc.DataDefinition.FormulaFields.Count; i++)
        {
            if(ReportDoc.DataDefinition.FormulaFields[i].FormulaName==
    						"{" + paramName + "}")
            tmpValue= ReportDoc.DataDefinition.FormulaFields[i].Text ;
        }
        return tmpValue;
    }
  4. Another button that changes the values of the report using the textbox text:

    private void SetParamValue (string paramName, string paramValue)
    {
        for(int i=0;i<ReportDoc.DataDefinition.FormulaFields.Count; i++)
        if(ReportDoc.DataDefinition.FormulaFields[i].FormulaName==
    					"{" + paramName + "}")
        ReportDoc.DataDefinition.FormulaFields[i].Text = "\"" +paramValue +"\"";
    }