Share via


Updating and Rebinding Data Source References

The ReportViewer control and the client report definition (.rdlc) file include references about the data sources that provide data to the report. At run time, all of the bindings and data source information must be in sync in order for the report output to contain the data that you expect. After you have bound data to a report and have already bound a report to a ReportViewer control, if you add or delete a dataset, modify a dataset that is used in a report, or make changes to the .rdlc file, you must update the bindings in the report and in the ReportViewer control before you deploy or run the application.

Updating Report Data in a Report Definition

Updating the report definition is necessary if you are copying .rdlc files between projects that have different datasets or if you modified the datasets used in your project. If you modify a dataset in the project by removing or renaming fields or tables, the report definition that is bound to the dataset will no longer contain valid references. To update the report definition, use the Report Data window as described in the following steps.

To update datasets in a report definition

  1. Open the client report definition (.rdlc) file in Visual Studio Report Designer.

  2. From the View menu, select Report Data. The Report Data window appears. You can use the following options:

    • To add a new dataset to the report definition, in the Report Data window's toolbar, select New, and then select Dataset.

    • To remove an existing dataset from the report definition, right-click the dataset and select Delete.

    • To modify an existing dataset, right-click the dataset and select Dataset Properties.

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

Rebinding Data Sources to the ReportViewer Control

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 data 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.

Note

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.

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.

See Also

Concepts

Creating Client Report Definition (.rdlc) Files

Creating Data Sources for a Report

Using the ReportViewer Tasks Smart Tags Panel

Configuring ReportViewer for Local Processing