Deborah's Developer MindScape

         Tips and Techniques for Web and .NET developers.

December 15, 2010

Tie a Report to Data from the Database

Filed under: C#,Reporting,VB.NET @ 2:33 pm

This prior post provided an overview of reporting in your WinForms or WebForms application. This post details how to tie your report to data directly from a database.

In this example, the report built in this prior post is tied directly to the data in the Customer table.

To Build a Data Source for a Report:

1) Display the report designer by double-clicking on the .rdlc file in the Solution Explorer.

2) Display the Data Sources Window (Data | Show Data Sources).

3) Click on the Add New Data Source button in the Data Sources Window toolbar.

4) Select to get the data from a Database and click Next.


5) Select Dataset (or Entity Data Model if you are using Entity Framework) and click Next.

NOTE: If you pick Entity Data Model, the additional dialogs will be different than shown below.


6) Select a connection or create a new connection and click Next.


7) Select to save the connection string and click Next.


8) Select which database objects to include in your dataset and click Finish. For this example, only the Customer data is required.


This adds a typed dataset (CustomerDataSet.xsd in this example) to the project.

To Build a Dataset for a Report:

A report is tied to a data source through a dataset. A dataset defines the data fields available to the report. You define a dataset based on a data source (created in the steps above).

This term "dataset" should not be confused with an ADO.NET dataset. This is not the same thing. In this context, a "dataset" is simply a set of data that can be used on a report.

NOTE: The "dataset" can instead be a list of business objects as detailed in this post.

1) Display the report in the designer by double-clicking on the .rdlc file in the Solution Explorer.

2) Display the Report Data Window (View | Report Data).

NOTE: If you do not see the Report Data menu option, ensure that the report designer is the active window.

3) Select New | Dataset from the Report Data window toolbar.

This creates a dataset that is accessible from the report.

4) Enter the name of the dataset, select the data source to use as the source of data for the dataset (defined in the prior set of steps), and select the data object within the data source to tie to the report.

The fields available to the report are then shown:


NOTE: By my programming convention, I name the report’s dataset "XXXDataSource" so as not to be confused with any typed dataset in the project.

The fields also appear in the Report Data window:


To Display Data from the Data Source on the Report:

1) Display the report in the designer by double-clicking on the .rdlc file in the Solution Explorer.

2) Hover over a cell in the data row, click on the field list (circled in red in the image), and select the field to display in the cell.


3) Repeat for each cell in the table.

4) To add fields from the dataset that are not already shown in the table, drag the field from the Report Data Window and drop it in the table.

Use this technique any time you want your report to pull its data directly from the database.


RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2021 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs