Skip to main content
All docs
V25.2
  • Bind a Report to a Parameterized Stored Database Procedure

    • 6 minutes to read

    This tutorial creates a Delphi or C++Builder application that obtains data for an ExpressReport from a stored database procedure and uses a report parameter as a procedure parameter. The tutorial uses the DevExpress Report Designer and Report Wizard at design time.

    VCL Reports: Stored Database Procedure and a Parameterized Report Preview

    Sample SQL Server Database

    The tutorial requires a configured relational database with a parameterized stored procedure. The described scenario is based on the Microsoft SQL Server with the Northwind sample database. To accomplish this tutorial, you can download the Northwind database or use an existing database in your development environment.

    Step 1 – Create and Configure a RAD Studio Project

    Place DevExpress Components on a Form

    Create a new Delphi or C++Builder project and place the following DevExpress components on a form:

    TdxReport
    Manages report document layouts, end-user dialogs, and related settings.
    TdxBackendDataConnectionManager
    Manages data sources for all reports in your application.

    Configure a Database (SQL) Connection

    1. Right-click the TdxBackendDataConnectionManager on the form and select Edit.
    2. Click the Plus button and select Database (SQL) in the drop-down list. A new connection (TdxBackendDatabaseSQLConnection) is added to the connection manager. Close the Edit dialog.
    3. Select the newly created connection in the Object Inspector. Set the connection’s DisplayName. Report Designer uses this name to display the connection in the UI.
    4. Paste the following string to the ConnectionString property:
      XpoProvider=MSSqlServer;Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;TrustServerCertificate=True;Persist Security Info=False;Encrypt=True;
      

    VCL Reports: A Form with Required Components and a Database Connection String

    Tip

    For additional information on using the SQL Server with ExpressReports, refer to the following guide:

    How to Use Microsoft SQL Server/Azure SQL Databases.

    Step 2 — Bind the Stored Procedure as a Report Data Source

    Create and Configure a Report Data Source

    Right-click the TdxReport component and select the Designer… option[1] to display the Report Designer dialog. Click the hamburger button to display the Report Designer menu.

    VCL Reports: The Report Designer Hamburger Button

    Select Add Data Source… to display available data source types:

    VCL Reports: The Report Designer Menu — Add Data Source

    Select Database and click Next:

    VCL Reports: The Data Source Wizard — Select Data Source, Database

    Specify data source settings:

    1. Select the data connection created earlier.
    2. Expand the Stored Procedures list and select CustOrdersDetail(@CustomerID).
    3. Expand the query parameters list and click the Edit button next to the @CustomerID parameter.
    4. In the Value field, fill in 11000 (this value will be updated later in this tutorial).
    5. Click Finish to save the configured report data source.

    VCL Reports: The Data Source Wizard — Data Source Settings for a Parameterized Stored Procedure

    Optional: Review the Created Data Source

    Review the Created Data Source

    Click the Fields button in the right panel of the Report Designer.

    Expand the created data source to review available data fields.

    VCL Reports: The Report Designer Dialog — Data Source Review

    Step 3 — Create a Report Layout Using the Report Wizard

    Click the hamburger button in the upper-left corner to display the Report Designer menu and select Design in Report Wizard:

    VCL Reports: The Report Designer Menu

    Select Table Report on the Select Report Type page to create a tabular layout and click Next:

    VCL Reports: The Report Wizard, Select 'Table Report' Type

    Select the previously created data source and click Next:

    VCL Reports: The Report Wizard, Select Data Source

    Define the report layout:

    1. Select the CustOrdersDetail query.
    2. Select all available data fields to display in the report.
    3. Add a summary field based on the ExtendedPrice field using the Sum function.
    4. Click Finish to return to the Report Designer.

    VCL Reports: The Report Wizard, Define the Report Layout

    The Report Designer dialog displays the generated report layout. To switch between Design and Preview modes[2], click corresponding buttons.

    VCL Reports: The Report Designer, Generated Report Layout

    Step 4 — Create and Pass a Report Parameter to the Stored Procedure

    Create a Report Parameter

    1. Click the Fields button in the right panel of the Report Designer.
    2. Click the Add parameter (plus) button next to Parameters.

    VCL Reports: The Report Designer — Add a Parameter

    Specify all required values in the Add Parameter form:

    1. Define the parameter’s Name and Description (display name).
    2. Select the Number (32 bit integer) data type.
    3. Scroll the form down and specify a predefined parameter value (Value) – for example, 11000.
    4. Click OK to save the parameter.

    VCL Reports: The 'Add Parameter' Form — Specify Parameter Values

    Pass the Report Parameter to the Stored Procedure

    1. Click the Fields button on the right panel of the Report Designer.
    2. Expand the previously created data source.
    3. Click the Edit query button next to CustOrdersDetail to open the Data Source Wizard. Click Next to open the Configure query parameters screen.

    VCL Reports: The Report Designer — Data Source, Edit Query

    1. Expand the OrderID parameter.
    2. Select Expression in the Type drop-down list.
    3. Paste ?OrderIDParameter in the Value field.
    4. Click Finish.

    VCL Reports: The Data Source Wizard — Configure Query Parameters

    Step 5 — Preview a Report and Save the Report Layout

    Preview a Parameterized Report

    1. Click PREVIEW in the upper-right corner of the Report Designer to switch to Preview mode.
    2. Define a different Order ID – for example, 11001.
    3. Click Submit to view a report for the specified Order ID.

    VCL Reports: The Report Designer — Report Preview Mode

    Save the Report Layout

    1. Switch to Design mode.
    2. Click the hamburger button and select the Save[3] option.
    3. Specify a report layout name (OrderDetails for example).

    VCL Reports: The Report Designer — Save the Report Layout

    Next Steps

    To display Report Designer/Report Viewer dialogs at runtime and deploy the resulting application, follow the steps of the basic Report Generation Tutorial:

    Display Report Viewer and Designer Dialogs at Runtime

    TdxReport used in this tutorial is a non-visual component. To display end-user dialogs at runtime using ShowDesigner and ShowViewer methods, refer to the following tutorial step: Display Report Viewer & Designer Dialogs at Runtime

    Build and Test Your Report Application

    All applications that include the TdxReport component require the WebView2 Runtime as a dependency. To automatically deploy this dependency using the post-build events in the RAD Studio IDE, refer to the following tutorial step: Build & Test Your First App

    Footnotes
    1. Alternatively, you can double-click the TdxReport component.

    2. You can switch to Preview mode at any moment to make certain that the resulting report document looks as intended.

    3. If you attempt to close the Report Designer dialog, you will be prompted to save pending report layout and data binding changes.

    See Also