ActiveReports 9 > ActiveReports User Guide > Concepts > Interactive Features > Parameters |
ActiveReports allows you to use parameters to filter or add the data to display in reports at runtime. You can either prompt users for parameters so that they control the output, or supply the parameters behind the scenes.
In a page report or a RDL report, each parameter must be entered at three locations: the Query page of the DataSet dialog, the Parameters page of the DataSet dialog, and the Report Parameters dialog for filtering data at runtime.
Query page of the DataSet dialog
On the Query page of the DataSet Dialog, enter the parameter in the SQL query. Use the syntax specific to your data source type to create a parameter. For example, with an OleDB data source, add a query like the following for a multi-value Movie Rating parameter:
SELECT * FROM Movie WHERE MPAA IN (?)
A query parameter can get its value from the Report Parameters collection (entered by the user or from a value you supply), a field in another dataset, or an expression.
Note: While using the SQL Client provider data source, specify the parameter as (@Parameter_Name) in your query. For example SELECT * FROM MOVIE WHERE MPAA IN (@Parameter1) |
Parameters page of the DataSet dialog
On the Parameters page of the DataSet Dialog, pass a Report Parameter into the parameter in your query. You can click the Add (+) icon at the top of the parameters list, enter parameter name, and supply a value like:
=Parameters!MPAA.Value
Report - Parameters dialog
The Report - Parameters dialog allows you to control how and whether a user interface is presented to your users for each parameter. You have to set the following properties in the dialog to create a parameter:
Parameter values are collected in the order they appear in the Report Parameters collection. You can change the order using the arrows in the Report - Parameters dialog.
General Tab
Available Values
These values are used to fill a drop-down list from which the end user can choose.
Default Values
Note: In the Available Values tab , the Value is what is passed to the query parameter, and the Label is what is shown to the user. For example, if the Value is an Employee Number, you might want to supply a more user-friendly Label showing Employee Names. |
You can access the Report - Parameters dialog through any one of the following:
The Report Parameters dialog contains a parameters page with a list of parameters and three tabs to set parameter properties. To add a parameter to the list, click the Add (+) icon and set the parameter properties in the three tabs described below.
If you want to run a report without prompting the user for a value at runtime, you need to set a default value for each parameter and the Hidden check box should be selected in the Report - Parameters dialog, General tab.
Subreport parameters are also considered as hidden parameters as a user can easily synchronize a subreport's data with that of the parent report. See Subreport in a RDL Report for further details.
Drill-Through parameters are also hidden parameters as drill-through links are used to navigate from one report to another. When you select Jump to report for the action, the parameters list is enabled.
In section report, you can use the Parameters collection to pass values directly into a control at runtime, or you can also use it to display a subset of data in a particular instance of a report.
There are several ways for setting up parameters in a report:
<%Name | PromptString | DefaultValue | DataType | PromptUser%>
Prompting for Parameter Values
In order to prompt the user for parameter values, all of the following must be in place:
When there are parameters in the collection and the ShowParameterUI property is set to True, the user prompt automatically displays when the report is run. When the user enters the requested values and clicks the OK button, the report gets displayed using the specified values.
Values of a parameter added through the Report Explorer can be applied to a parameter in the SQL query by specifying the param:
prefix for a parameter in the SQL query. This prefix relates the current parameter to the one in the Report Explorer.
For e.g., select * from CUSTOMERS where CustomerName = '<%param:Parameter1%>'
. In this case, the parameter with the param:
prefix in the SQL query is updated with values of the corresponding parameter in the Report Explorer.
Note:
|
Adding Parameters to the Parameters Collection via the SQL Query
When you add a single parameter to a report's Parameters collection via the SQL query, the query looks like this:
SQL Query. |
Copy Code
|
---|---|
SELECT * FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID WHERE Products.SupplierID = <%SupplierID|Enter a Supplier ID|1|S|True%> |
There are five values in the parameter syntax, separated by the pipe character: |
Only the first value (Name) is required, but if you do not specify the third value (DefaultValue), the field list is not populated at design time. You can provide only the Name value and no pipes, or if you wish to provide some, but not all of the values, simply provide pipes with no space between them for the missing values. For example, <%ProductID||||False%>
Name: This is the unique name of the parameter, and corresponds to the Key property in parameters entered via code.
PromptString: This string is displayed in the user prompt to let the user know what sort of value to enter.
DefaultValue: Providing a default value to use for the parameter allows ActiveReports to populate the bound fields list while you are designing your report, enabling you to drag fields onto the report. It also populates the user prompt so that the user can simply click the OK button to accept the default value.
Type: This value, which defaults to S for string, tells ActiveReports what type of data the parameter represents. It also dictates the type of control used in the user prompt. The type can be one of three values.
'<%MyStringParameter%>'
<%MyStringParameter||"DefaultValue"|S|False%>
#<%MyDateParameter%>#