Using parameters in a report

Top  Previous  Next

You can refer to a parameter from an expression using square brackets:

 

[Parameter name]

 

To a nested parameter you need to refer using this method:

 

[Parent parameter.Child parameter]

 

Since a parameter has got a definite type (it is given in the DataType property), then with parameters, you can perform those actions which are allowed for data type. So, string type parameters can be used in an expression the following way:

 

[StringParameter].Substring(0, 2)

 

Let us see one example of using parameters. Assuming we have a report which prints "Employees" table. We want to modify the report to print information about an employee with an indicated number. To do this, we need to filter the data on the "EmployeeID" data column. Create a parameter with "EmployeeID" name. Indicate parameter's type - Int32, as exactly this type has the "EmployeeID" data column. To filter an employee with an indicated ID we need to enter "Data" band editor and indicate the following expression in "Filter" tab:

 

[Employees.EmployeeID] == [EmployeeID]

 

To pass parameter value from your program to the report, use the following code:

 

report1.SetParameterValue("EmployeeID"2);