Passing a value to the parameter
Parameters are often used to ask a value from the user. Let us look at two ways to pass a value to the query parameter.
In the first way, you pass a value programmatically. Since there is no easy way to pass a value directly to the query parameter, you need to use the report parameter, which can be easily set via code. You should do the following:
- Create the report parameter (for more details about parameters, refer to the section "Report parameters"). Set the same
DataTypefor the report parameter, as it is used in the query parameter. - In the
Expressionproperty of the query parameter, refer to a report parameter, for example:
[MyReportParameter]
- Pass a value to the report parameter:
report1.SetParameterValue("MyReportParameter", 10);
In the second way, you use the dialogue forms to do this (for more details about dialogs, refer to the chapter "Dialogue forms"). For example, if you need to ask a string-type value, do the following:
- add a dialog into your report;
- put the "TextBoxControl" on it. This control will be used to enter the string value;
- set up the parameter as follows:
Name=param1
DataType=VarChar
DefaultValue= (empty string)
Expression=TextBox1.Text
Size=255
Where TextBox1 is a control which contains a value entered by the user.