Updating and Rebinding Data Source References (Visual Studio Report Designer)

The ReportViewer control and the client report definition (.rdlc) file include references about the data sources that provide data to the report. If you convert report definitions, add or delete a dataset, or modify a dataset that is used in a report, you must update all data source references and bindings before you deploy or run the application.

Overview of Data Source References Used by ReportViewer Controls and Reports

Data source information is used by the controls and reports in several ways. First, the report definition uses embedded schema information to make the association between items in the report layout and the data that is eventually merged into the layout. Second, the ReportViewer control requires data source bindings so that you can pass data to it at run time.

At run time, all of the bindings and data source information must be in sync in order for the report to contain the data that you expect. A variety of options are provided to help you keep the data source information synchronized throughout the development cycle as you modify the reports and datasets that are used in your application. The following list summarizes the different options that are available:

  • Use the Choose Data Sources task in the ReportViewer Tasks smart tags panel to bind a data source to a client report definition (.rdlc) file that you converted from a server report definition (.rdl) file.

  • Use the Rebind Data Sources task in the ReportViewer Tasks smart tags panel to synchronize the control and report definition with modified datasets.

  • Use the Report Data Sources dialog box on the Report menu to update the schema information stored in the report definition file. The Report menu is available when you edit a client report definition (.rdlc) file in graphical design mode.

Updating Data Source References in a Report Definition

The report definition includes dataset elements that define the data source structure used by the report. The dataset elements are added to the report definition during report design. A new element is added each time you drag a specific field to a data region or text box in the report.

Updating the report definition is necessary if you are copying report definition files between projects that have different data sources or if you modified the datasets used in your project. If you subsequently modify the actual dataset in the project by removing or renaming fields or tables, the report definition will no longer contain valid references. To update the report definition, use the Data Sources dialog box as described in the following steps.

How to Update References in a Report Definition

  1. Open the client report definition (.rdlc) file in graphical design mode.

  2. From the Report menu, select Data Sources. The Report Data Sources dialog box appears. You can use the following options:

    • To add a new dataset to the report definition, select a Project data source and click Add to report. In most cases, this option is not necessary. Project data sources are added to the report definition automatically when you drag fields to the report layout.

    • To remove an existing dataset reference from the report definition, select the dataset and click Remove.

    • If you renamed a dataset in your project, you can use the Report Data Sources dialog box to update the dataset name in the report definition. Click the Rename button to set the dataset name in overwrite mode, and then type the new name.

  3. Click Refresh All to update the report definition file with your changes.

Rebinding Data Sources to the ReportViewer Control

The ReportViewer control requires data bindings to access application data sources at run time. Data bindings are created for the control when you select a client report definition (.rdlc) file.

Rebinding a data source is necessary if you modify a report definition that has already been bound to a control, if you modify the dataset after the control has been bound to a form or Web page, or if you add a new dataset to the report. All of these scenarios result in bindings that are out-of-date. Use the Rebind Data Sources task on the ReportViewer Tasks smart tags panel to update the data bindings in application code.

NoteNote

Not all modifications to a report definition require that you rebind a data source. Rearranging items, formatting items, or reusing the same data-bound field in multiple data regions are examples of modifications that do not invalidate existing data bindings. Similarly, if you modify a part of the data source that is not used in the report, you do not need to update the bindings.

How to Rebind Data Sources

  1. Open the form or Web page that contains the ReportViewer control.

  2. In the ReportViewer Tasks smart tags panel, click Rebind Data Sources. You can inspect the code behind the form or page to confirm the changes.

Choosing Data Sources for the ReportViewer Control

When you convert a server report definition (.rdl) file to a client report definition (.rdlc), you must ensure that your application includes data binding code for the ReportViewer control. The data binding code is generated automatically when you create a .rdlc file from a report template. However, the data binding code will be missing if you create the .rdlc file in some other way. To add the data binding code, use the Choose Data Sources task on the ReportViewer Tasks smart tags panel. To learn more about converting report definitions, see Converting RDL and RDLC Files.

How to Add Data Source Bindings

  1. Open the form or Web page that contains the ReportViewer control.

  2. In the ReportViewer Tasks smart tags panel, click Choose Data Sources. You can inspect the code behind the form or page to confirm the changes.

See Also

Community Additions

ADD
Show: