ActiveReports 15 .NET Edition
ActiveReports 15 User Guide / Samples and Walkthroughs / Walkthroughs / Page Report/RDL Report Walkthroughs / Preview / Parameterized Reports
In This Topic
    Parameterized Reports
    In This Topic

    You can create a parameterized report with ActiveReports and provide the ability to select multiple values for those who want to view data for several items.

    This walkthrough illustrates how to create a report with multi-value parameters and an option to select all of the data.

    The walkthrough is split up into the following activities:

    Note:
    • This walkthrough uses the Products table from the Nwind database. The NWIND.mdb file can be downloaded from GitHub: ..\Samples15\Data\NWIND.mdb.
    • Although this walkthrough uses RDL report, you can also implement this using Page report.

    When you complete this walkthrough you get a layout that looks similar to the following at design time and at run time.

    Design-Time Layout

    Parameterized report at design time

    Run-Time Layout

    Parameterized report at run time

    Parameterized report at run time

    To add an ActiveReport to the Visual Studio project

    1. Create a new Visual Studio project.
    2. From the Project menu, select Add New Item.
    3. In the Add New Item dialog that appears, select ActiveReports 15 RDL Report and in the Name field, rename the file as Product Details.
    4. Click the Add to open a new rdl report in the designer.

    See Basic Concepts for information on adding different report layouts.

    To connect the report to a data source

    1. In the Report Explorer, right-click the Data Sources node and select the Add Data Source option or select Data Source from the Add button.
      Adding a datasource
    2. In the Report Data Source Dialog that appears, select the General page and in the Name field, enter a name like ReportData.
    3. On this page, create a connection to the Nwind database. See Connect to a Data Source for information on connecting to a data source.

    To add a dataset to populate the parameter values

    1. In the Report Explorer, right-click the data source node and select the Add Data Set option.
    2. In the DataSet Dialog that appears, select the General page and enter the name of the dataset as DataSet1. This name appears as a child node to the data source icon in the Report Explorer.
    3. On the Query page of this dialog, in the Query field enter the following SQL query.
      SQL Query
      Copy Code
      select distinct productName from Products
      
    4. Click the Validate DataSet icon at the top right hand corner above the Query box to validate the query.
    5. Click OK to close the dialog. You see the data set, DataSet1, and the field, productName in the Report Explorer.

    To add a parameter to the report

    1. In the Report Explorer, select the Parameters node.
    2. Right-click the node and select Add Parameter to open the Report - Parameters dialog.
    3. In the dialog box that appears, click the Add(+) button to add a new parameter in the list.
    4. Set properties in the following fields below the parameters list.

      In the General tab:

      • Name: ReportParameter1
      • DataType: String
      • Text for prompting users for a value: Select the product name.
      • Select the check box next to Multivalue to allow users to select more than one product name from the list.
      • Enter Value for 'Select All': 1

      In the Available Values tab, select From query:

      • DataSet: DataSet1
      • Value: productName
      • Label: productName
        Note: The name of the parameter you enter must exactly match the name of the parameter in the linked report, and it is case sensitive. You can pass a value from the current report to the parameter in the Value column of the list. If a value is not supplied for an expected parameter in the linked report, or if the parameter names do not match, the linked report will not run.
    5. Click OK to close the dialog and add the parameter to the collection. The ReportParameter1 parameter appears under the Parameters node in the Report Explorer.

    To add a dataset with a parameter

    1. In the Report Explorer, right-click the data source node and select the Add Data Set option.
    2. In the DataSet Dialog that appears, select the General page and enter the name of the dataset as DataSet2. This name appears as a child node to the data source icon in the Report Explorer.
    3. On the Parameters page under Parameter Name enter ReportParameter1.
    4. Under Value enter =Parameters!ReportParameter1.Value.
    5. On the Parameters page under Parameter Name enter Parameter1.
    6. Under Value enter =Parameters!ReportParameter1.Value.
    7. On the Query page of this dialog, in the Query field enter the following SQL query.
      SQL Query
      Copy Code
      select * from products where ProductName in (?) OR '1' in (?)
      
    8. Click the Validate DataSet icon at the top right hand corner above the Query box to validate the query.
    9. Click OK to close the dialog. Your data set and queried fields appear as nodes in the Report Explorer.

    To create a layout for the report

    1. From the toolbox, drag a Table control onto the design surface and in the Properties window, set the following properties.
      Property Name Property Value
      Location 0.5in, 0.25in
      DataSetName DataSet2
      Size 4.8in, 0.75in
    2. In the Report Explorer, from the DataSet2 dataset drag the following fields into the detail row of the table and set their properties as in the following table.
      Field Column Width
      ProductName TableColumn1 2.37in
      UnitPrice TableColumn2 0.67in
      UnitsOnOrder TableColumn3 1.62in
    3. Static labels with the field names are automatically created in the table header row. To improve the appearance of the report, select the table header row, and set the BackgroundColor to DeepSkyBlue.

    To view the report

    • Click the preview tab to view the report at design time.

    OR

    See Also