Passing a value to the parameter

Top  Previous  Next

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 (we will discuss the report parameters later in this chapter). Set the same DataType for the report parameter, as it is used in the query parameter.
In the "Expression" property 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 (dialogue forms will be discussed later). 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.