Skip to main content

Create a Master-Detail Report with a Detail Report Band in the VS Report Designer

  • 4 minutes to read

A Master-Detail report allows you to display related and hierarchical data, such as customers and their orders, or orders and their details.

This tutorial illustrates how to display hierarchical data in a master-detail report using nested DetailReportBand elements. This technique allows you to create a report by database queries that are tied by a master-detail relationship at the data source level.

HowTo - MasterDetailBands_5

Prerequisites

To get started with this tutorial, open an existing reporting application or create a new application. You can review the following section that explains how to create a reporting application on different platforms: Add a Report to Your .NET Application.

Difference Between a Detail Band and a Subreport

You can create a Master-Detail report in two ways: with the help of a detail band or a subreport. Before you begin, review the following key points that help you select a suitable variant for your scenario:

Detail Report Band
  • A Detail Report Band is a section within the same master report that displays detailed data. This band requires relations in a data source and is connected to the data source within the master report’s structure.
  • You can integrate parent and child data without having to manage separate reports.
  • You can print a Detail Report Band only under the master band that fills the entire width of the report. For example, you cannot use it in side-by-side reports.
Subreport
  • A Subreport is a separate report that is embedded into the master report. You can design and maintain it independently and reuse it in multiple master reports.
  • A Subreport gets its data from a separate data source and uses parameters to connect with the master report. The master report passes a value (such as an ID or a key) to the Subreport, which uses that value to filter its data.
  • A subreport offers more design possibilities. For example, you can use a subreport to create side-by-side reports.

Create a Master-Detail Report with a Detail Report Band

Do the following to create a master-detail report:

  1. Add a SQL data source and provide it with a master-detail relationship as described in the Bind a Report to a Database topic. In this example, we will use the Categories and Products data tables of the sample Northwind database to establish the Categories-Products master-detail relationship.

    The Field List will be updated to reflect the new hierarchy of the report’s data.

    how-to-sql-data-source06

  2. To create a detail report, right-click the report’s Detail band. In the invoked context menu, point to Insert Detail Report and click “CategoriesProducts”.

    HowTo - MasterDetailBands_2

  3. If the DetailReport is properly bound to the data, the following properties of the created DetailReportBand are set automatically:

    detail-report-band-data-source-properties

  4. Drag the CategoryName and Description fields from the Field List window and drop them onto the Detail band.

    HowTo - MasterDetailBands_3

  5. Drop the ProductName and UnitPrice fields from the Field List’s CategoriesProducts section onto the DetailReport‘s Detail1 band.

    HowTo - MasterDetailBands_4

    Note

    Note that these fields must be taken from the CategoriesProducts relationship, and not from the Products table. Otherwise, the report will display only the first record of the Products table for each category, as many times as there are records in each category.

    You can convert the dropped labels to a table to simplify control alignment. See the Convert Labels to Table topic for more information.

Preview the Result

Your report is finished. In Visual Studio, you can switch to the Preview tab to preview the report:

HowTo - MasterDetailBands- Preview the Result

You may want to customize the visual style and layout as an additional step. For example, if you want to make the detail sections collapse or expand when you click them in Print Preview, see Create Drill-Down Reports.

Create a Simple Master-Detail Report in Code

See the following example for information on how to work with DetailBand in code: Create a Simple Data-Bound Report.

Create a Master-Detail Report with a Detail Report Band in the End-User Report Designer

Tutorials that explain how to create different reports in EUD Report Designers for WinForms and Web are included in the End-User Documentation online help section: