The requested page is not available for the requested platform. You are viewing the content for Default platform.

Register Predefined Data Sources

  • 2 min to read

This document describes how to provide data sources to the Web Report Designer. These data sources are available for all reports.

  1. Add a new Report Designer Model (for instance, the ReportDesignerModel file) to the Models folder and insert the following code:

    using DevExpress.XtraReports.UI;
    namespace WebApplication1.Models {
        public class ReportDesignerModel {
            public XtraReport Report { get; set; }
            public Dictionary<string, object> DataSources { get; set; }
  2. Open the Controller file and create data sources.

    using Microsoft.AspNetCore.Mvc;
    using DevExpress.DataAccess.Sql;
    using DevExpress.DataAccess.ConnectionParameters;
    using DevExpress.DataAccess.Json;
    using DevExpress.XtraReports.UI;
    using WebApplication1.Models;
    // ...
    public class HomeController : Controller {
        public IActionResult Index() {
            // Create a SQL data source.
            MsSqlConnectionParameters parameters = new MsSqlConnectionParameters("localhost",
                "dbName", "userName", "password", MsSqlAuthorizationType.SqlServer);
            SqlDataSource dataSource = new SqlDataSource(parameters);
            SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products");
            // Create a JSON data source.
            JsonDataSource jsonDataSource = new JsonDataSource();
            jsonDataSource.JsonSource = new UriJsonSource(new Uri(""));
            var model = new ReportDesignerModel
                // Open your report here.
                Report = new XtraReport()
            model.DataSources.Add("Northwind", dataSource);
            model.DataSources.Add("JsonDataSource", jsonDataSource);
            return View(model);
        // ...
  3. In the View file, modify your code to obtain data sources from the model and add them to the Report Designer's DataSources collection.

    @model ReportDesignerModel
        .DataSources(configureDS => { foreach (var ds in Model.DataSources) { configureDS.Add(ds.Key, ds.Value); } });
  4. Install the Newtonsoft.Json package if you add JSON data sources.

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