Skip to main content
All docs
V24.1

DataSourceManager.ReplaceDataSource(XtraReport, Object, Object, Boolean) Method

Replaces a report’s current data source with the specified data source.

Namespace: DevExpress.XtraReports

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public static void ReplaceDataSource(
    XtraReport report,
    object oldDataSource,
    object newDataSource,
    bool includeSubReports = false
)

Parameters

Name Type Description
report XtraReport

A report instance.

oldDataSource Object

The report’s data source.

newDataSource Object

A new report data source.

Optional Parameters

Name Type Default Description
includeSubReports Boolean False

true to replace data sources of subreports with the specified data source; otherwise, false.

Remarks

Consider the following specifics when you use the ReplaceDataSource method:

  • If your new data source has the same type as the initial report data source, you can update settings of the initial data source. If types of the new and initial data sources are different, we recommend you create a new data source and call the ReplaceDataSource method to assign it to the report.
  • Make sure that schemas of the new and initial report data sources match. Otherwise, bindings in your report might not work as expected, and therefore, report data can be displayed differently than in the report with the initial data source.

Example

The following code sample shows how to replace a report’s initial data source with a JSON data source:

using DevExpress.XtraReports;
using DevExpress.DataAccess.Json;
//...

var report = new XtraReport1();

var jsonDataSource = new JsonDataSource {/* ... */};

DataSourceManager.ReplaceDataSource(report, report.DataSource, jsonDataSource);
See Also