[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Collapse]Reporting
 [Expand]Product Information
 [Expand]Get Started with DevExpress Reporting
 [Expand]Create Popular Reports
 [Collapse]Detailed Guide to DevExpress Reporting
   Introduction to Banded Reports
  [Collapse]Provide Data to Reports
   [Collapse]Bind a Report to a Data Source
    [Collapse]SQL Database
      Bind a Report to a Database
      Bind a Report to a Stored Procedure
      Bind a Report to a Data Source Schema
      Bind a Report to an MDB Database (Runtime Sample)
      Bind a Report to a Microsoft SQL Server Database (Runtime Sample)
      Register a Custom Schema Provider for a Synonym Database
    [Expand]XML File
    [Expand]Entity Framework Data Source
    [Expand]Object Data Source
    [Expand]List Object
    [Expand]Excel Data Source
    [Expand]JSON Data Source
    [Expand]XPO Data Source
     Standard .NET Data Providers
     Bind a Report to Multiple Data Sources
     Bind a Report to Multiple Data Tables
   [Expand]Bind Report Controls to Data
  [Expand]Use Report Controls
  [Expand]Shape Report Data
   Lay out Dynamic Report Contents
  [Expand]Customize Appearance
  [Expand]Add Navigation
  [Expand]Provide Interactivity
  [Expand]Add Extra Information
  [Expand]Merge Reports
  [Expand]Use Expressions
  [Expand]Store and Distribute Reports
  [Expand]Reporting API
 [Expand]Visual Studio Report Designer
 [Expand]Create End-User Reporting Applications
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Bind a Report to a Database

This tutorial demonstrates how to bind a report to a hierarchical data source at design time in Visual Studio and specify a master-detail relationship between data source queries.

Do the following to accomplish this task:

  1. Click the report's smart tag. In the invoked actions list, expand the drop-down menu for the DataSource property and click Add Report Data Source...

  2. On the first page of the invoked Data Source Wizard, select Database and click Next to proceed.

  3. The next page allows you to specify whether you want to use an existing data connection available in the Visual Studio® Server Explorer or create a new data connection from scratch. Select the first option to create a new connection and click Next.

  4. On the next page, you can define a custom connection string, or select one of the supported data providers.

    Depending on the data provider selected, it may be necessary to specify additional connection options (such as the authentication type and database name) on this page.

    In this example, the report will be bound to a sample Northwind database hosted on a Microsoft SQL Server.

    To proceed to the next wizard page, click Next.

  5. Click Next on the following page to save the created connection string to the configuration file.

  6. On the next page, you can choose which tables, views and/or stored procedures to add to the report.

    To create a master-detail report, select two or more tables and click Manage Relations.

    In the invoked editor, connect the required key fields (columns) using drag and drop.

    Click OK to close the editor.

    Note

    When you are required to shape data at the level of a data source, you can create custom queries by expanding the Queries category and clicking the button.

    This will invoke the Query Builder where you can create complex queries by joining multiple tables, filtering, sorting and grouping their data, as well as calculating various aggregate functions.

    Although it is also possible to join different tables within a single query, creating hierarchical data sources is preferred in most cases to provide better performance (in general, master-detail reports are generated faster than similar-looking reports created by grouping "flat" data sources).

    Click Finish to complete the Data Source Wizard. If the selected queries or stored procedures contain any parameters, you can go to the next wizard page and define their values.

The newly created SQL data source will be displayed in the Components node of the Report Explorer. Additionally, the hierarchy of the data source will be reflected by the Field List. In both panels, you can right-click the data source to access its settings.

Expanded See Also

Is this topic helpful?​​​​​​​