How to: Bind a Report to Multiple MDB Data Sources (Runtime Sample)

  • 2 minutes to read

This tutorial describes the steps used to bind your Snap report to multiple unrelated data sources simultaneously. This is useful when you wish to allow your end-user to choose from multiple data sources or create combined reports.

Follow these steps to create a report with multiple data sources.

  1. Start Microsoft Visual Studio 2012, 2013, 2015, 2017 or 2019, and create a new Windows Forms application or open an existing one.
  2. Drop the SnapControl from the DX20.1: Reporting Toolbox tab on the application's main form.
  3. To connect the application to data, handle the Load event of the application's main form and add the following code in the event handler.

    
    using System;
    using System.Data;
    using System.Windows.Forms;
    using System.Data.OleDb;
    using DevExpress.Snap.Core.API;
    // ...
    
    string PathToNwind = 
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Public\\Documents\\DevExpress Demos 14.1\\Components\\Data\\nwind.mdb";
    string PathToCarsDB = 
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Public\\Documents\\DevExpress Demos 14.1\\Components\\Data\\CarsDB.mdb";
    DataSet ds = new DataSet();
    
    private void Form1_Load(object sender, EventArgs e) {
        snapControl1.Document.BeginUpdateDataSource();
        AddDataSource(PathToNwind, "Categories");
        AddDataSource(PathToCarsDB, "Cars");
        snapControl1.Document.EndUpdateDataSource();
    }
    
    public void AddDataSource(string path, string table) {
        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + table, @path);
        adapter.Fill(ds, table);
        snapControl1.Document.DataSources.Add(new DataSourceInfo(table, ds));
    }
    

The Snap application is now ready. Run it to create your report.

To design the report layout, drop fields from the Data Explorer onto the report editing surface.

Snap_MultipleDataSources