ActiveReports allows you to use parameters to filter or add the data to display in reports at run time. You can either prompt users for parameters so that they control the output, or supply the parameters behind the scenes.
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. Syntax for adding a parameter in your query might differ depending upon the data source that you are using. Use the syntax specific to your data source type to create a parameter.
Parameterized query for different data sources are as follows:
Data Source | Parameter Syntax | Example |
---|---|---|
OleDB | (?) | SELECT * FROM Customer WHERE (CustomerID = ? AND AccountNumber = ?) |
ODBC | @ParameterName | SELECT * FROM Customer WHERE (CustomerID = @CustomerID AND AccountNumber = @AccountNumber) |
SQL Client | @ParameterName | SELECT * FROM Customer WHERE (CustomerID = @CustomerID AND AccountNumber = @AccountNumber) |
OracleDB | :ParameterName | SELECT * FROM Customer WHERE CustomerID = :CustomerID AND AccountNumber = :AccountNumber |
For example if Parameter value contains 'Chr(&H000)' code for Null value, then the parameter dropdown displays '0x0'.
In a page report or a RDL report, the easiest way to build queries with parameters is to use the Visual Query Designer, as it automatically sets up each parameter.
In the DataSet dialog, click on to access Visual Query Designer for creating SQL queries. See Query Building With Visual Query Designer for further information on how to create a parameterized query using the interactive query designer.
However, if you would like to do it manually, you must enter each parameter in three locations: the Report Parameters dialog (for filtering data at run time), the Parameters page of the DataSet dialog, and the Query page of the DataSet dialog.
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
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.
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
Query page of the DataSet dialog
SELECT * FROM Movie WHERE (MPAA = ? AND YearReleased = ?)
If you want to run a report without prompting the user for a value at run time, 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 Subreports in Page/RDL Reports 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 run time, 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: Within the same report, you can prompt users for some parameters and not for others by setting the PromptUser property to True on some and False on others. However, if the report object's ShowParameterUI property is set to False, the user prompt does not display for any parameters regardless of its PromptUser setting.
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%> |
You can also create a parameterized query from the Visual Query Designer. See Query Building With Visual Query Designer for further information on how to create a parameterized query using the interactive query designer.
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.
DataType: 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%>#