Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / C#
Article

Passing Parameters to Crystal Reports at Runtime

Rate me:
Please Sign up or sign in to vote.
2.91/5 (27 votes)
20 Nov 2003CPOL 156.2K   3.6K   34   10
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:

    C#
    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:

    C#
    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 +"\"";
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Claro Colombia
Colombia Colombia
German A. Fajardo G.
Web Developper
SQL Server Developer
PL/SQL Developer
Business Intelligence Desiggn Developer
ITIL Services Implementation.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Jackson K T16-Aug-12 20:10
professionalJackson K T16-Aug-12 20:10 
GeneralMy vote of 5 Pin
premkumar.r29-Jul-11 0:06
premkumar.r29-Jul-11 0:06 
GeneralMy vote of 2 Pin
inamgul26-Apr-11 20:48
inamgul26-Apr-11 20:48 
GeneralMy vote of 5 Pin
adnanrehmankhan19-Jul-10 0:02
adnanrehmankhan19-Jul-10 0:02 
Generalchange the report's font at run time Pin
da_dhanaraj3-Nov-08 8:09
da_dhanaraj3-Nov-08 8:09 
GeneralExcellent! Pin
Bit-Smacker9-Sep-08 9:18
Bit-Smacker9-Sep-08 9:18 
Generalthanx Pin
sajat29-Apr-08 2:05
sajat29-Apr-08 2:05 
GeneralThanks Pin
zaider2-Apr-08 9:17
zaider2-Apr-08 9:17 
GeneralThank Pin
Escocia12-Jun-07 1:05
Escocia12-Jun-07 1:05 
GeneralWin Forms Grid Data and more Pin
Anonymous10-Apr-05 23:37
Anonymous10-Apr-05 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.