Skip to main content
A newer version of this page is available. .

Register Default Data Sources

  • 2 minutes to read

This document describes how to provide a Web Report Designer with a set of default data sources available for all report design sessions.

To do this, create the required data sources and add them to the ReportDesignerSettings.DataSources collection of an object storing Report Designer settings.

@using DevExpress.DataAccess.ConnectionParameters
@using DevExpress.DataAccess.Sql

@Html.DevExpress().ReportDesigner(settings => {
    settings.Name = "ReportDesigner";

    // Create a SQL data source with specified connection parameters.
    MsSqlConnectionParameters connectionParameters =
            new MsSqlConnectionParameters("localhost", "Northwind", null, null, MsSqlAuthorizationType.Windows);
    DevExpress.DataAccess.Sql.SqlDataSource ds = new DevExpress.DataAccess.Sql.SqlDataSource(connectionParameters);

    // Create a custom SQL query to access the Products data table.
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "Products";
    query.Sql = "SELECT * FROM Products";
    ds.Queries.Add(query);
    ds.RebuildResultSchema();

    // Add the created data source to the list of default data sources. 
    settings.DataSources.Add("Northwind", ds);

}).Bind(new XtraReport()).GetHtml()

When an end-user adds one of the available data sources to a report, the data source object is cloned and its created copy is assigned to the XtraReportBase.DataSource property. This is required to properly serialize the data source settings along with the report layout data when the report is saved.

web-designer-field-list-add-data-source

For related code samples, please refer to the following online examples.

See Also