Back to Devexpress

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

xtrareports-devexpress-dot-xtrareports-dot-datasourcemanager-dot-replacedatasource-x28-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-system-dot-object-system-dot-object-system-dot-boolean-x29.md

latest3.3 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public static void ReplaceDataSource(
    XtraReport report,
    object oldDataSource,
    object newDataSource,
    bool includeSubReports = false
)
vb
Public Shared Sub ReplaceDataSource(
    report As XtraReport,
    oldDataSource As Object,
    newDataSource As Object,
    includeSubReports As Boolean = False
)

Parameters

NameTypeDescription
reportXtraReport

A report instance.

| | oldDataSource | Object |

The report’s data source.

| | newDataSource | Object |

A new report data source.

|

Optional Parameters

NameTypeDefaultDescription
includeSubReportsBooleanFalse

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:

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

var report = new XtraReport1();

var jsonDataSource = new JsonDataSource;

DataSourceManager.ReplaceDataSource(report, report.DataSource, jsonDataSource);
vb
Imports DevExpress.XtraReports
Imports DevExpress.DataAccess.Json
'...

Private report = New XtraReport1()

Private jsonDataSource = New JsonDataSource()

DataSourceManager.ReplaceDataSource(report, report.DataSource, jsonDataSource)

See Also

DataSourceManager Class

DataSourceManager Members

DevExpress.XtraReports Namespace