To pass the parameter value dynamically at run time, first we have to create a parameter field in crystal report by using Parameter Fields option from Field Explorer.

As you can see in the below image, I have taken a designation table from the database and added to the selected table list

Dynamically Pass Parameter Value in Crystal Report

After that I had selected a column from the table and show them in the details section of the crystal report.

Dynamically Pass Parameter Value in Crystal Report

For creating a parameter field right clicks on the Parameter Fields option and click on New option to create a new parameter field.

Dynamically Pass Parameter Value in Crystal Report

In the new parameter section of the crystal report, give the name of the parameter and Click OK. Here I gave designation as a parameter name.

Dynamically Pass Parameter Value in Crystal Report

After that take Record selection formula from the special field in the crystal report and then right click on the Record selection formula and Select Expert à Record.

Dynamically Pass Parameter Value in Crystal Report

After Select Expert à Record Choose Field dialog box will open, select the field from the table on the basis of which you want to display the report and click OK. Here I selected an employee_designation field as a base.

Dynamically Pass Parameter Value in Crystal Report

After that Select Expert – Record window will open, select the parameter field from the right Dropdown list and also select the is equal to option from the left Dropdown list if you want to show the details according to parameter value passed.

Dynamically Pass Parameter Value in Crystal Report

Design application form as shown below by using label, textbox, button, and crystalReportViewer control from the toolbox.

Dynamically Pass Parameter Value in Crystal Report

After putting controls on form let’s move to the coding part and on the click event of button write the following code to pass value in the parameter field.

    Private void button1_Click(object sender, EventArgs e)

              //creating an object of Report Document class
            ReportDocument reportDocument = new ReportDocument();

              //creating an object of ParameterField class
            ParameterField paramField = new ParameterField();

              //creating an object of ParameterFields class
            ParameterFields paramFields = new ParameterFields();

              //creating an object of ParameterDiscreteValue class
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

     //set the parameter field name
            paramField.Name = "designation";

              //set the parameter value
            paramDiscreteValue.Value = textBox1.Text;

              //add the parameter value in the ParameterField object

              //add the parameter in the ParameterFields object

              //set the parameterfield information in the crystal report
            crystalReportViewer1.ParameterFieldInfo = paramFields;

              //preparing root for preview
            reportDocument.Load("D:\\rohit\\crystal reports\\CrystalReport1.rpt");
            crystalReportViewer1.ReportSource = reportDocument;

Dynamically Pass Parameter Value in Crystal Report

Here we can get output according to parameter passed for employee_designation field.

  Modified On Sep-25-2019 02:26:58 AM
  1. I am getting load report failed ,,,,,, if I use
    reportDocument.Load("|Data Directory|\\Forms\\readngrpt.rpt");   // reportDocument.Load("|DataDirectory|
    and if i give full address it is working
  1. I get the error"Load Report Failed".I used full path of the report like"C:Users\\innovit7\\Desktop\\26.12.2015\\PayRoll123\\PayRoll\\EmployeeCrystalReport.rpt" and also using Data Directory  like"|Data Directory|\\PayRoll\\EmployeeCrystalReport.rpt".But i still get the error.How can i Solbve it.Please help me....
    Thanks in Advance
  1. why are not show  question in the report...using window form.

    my code

     DataSet ds = new DataSet();

                    ReportDocument rptDoc = new ReportDocument();

                    rptDoc.Load(@"D:/Jignesh_Work/Windows App/QuestionPaper/Ass3/Ass3/ViewQuestionNew.rpt");




                    for (int i = 0; i < dgvViewque.Rows.Count; i++)


                        rptDoc.SetParameterValue("Question", dgvViewque.Rows[i].Cells[0].Value.ToString());

                        rptDoc.SetParameterValue("Date", dgvViewque.Rows[i].Cells["date"].Value.ToString());

                        rptDoc.SetParameterValue("Time", dgvViewque.Rows[i].Cells["time"].Value.ToString());

                        rptDoc.SetParameterValue("Class", dgvViewque.Rows[i].Cells["class"].Value.ToString());

                        rptDoc.SetParameterValue("Sub", dgvViewque.Rows[i].Cells["subject"].Value.ToString());

                        rptDoc.SetParameterValue("Mark", dgvViewque.Rows[i].Cells["mark"].Value.ToString());

                        rptDoc.SetParameterValue("School", dt1.Rows[0]["name"].ToString());

                        rptDoc.SetParameterValue("Address", dt1.Rows[0]["address"].ToString());

                        crystalReportViewer1.ReportSource = rptDoc;



Leave Comment