[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Collapse]Snap
   [Expand]Product Information
   [Collapse]Getting Started
     Lesson 1 - Create a Snap Application
     Lesson 2 - Connect a Document to Data
     Lesson 3 - Create a Mail Merge Report
     Lesson 4 - Create a Tabular Report
   [Expand]Graphical User Interface
    Supported Formats
   [Expand]Developer Guidelines
   [Expand]Data Acquisition
   [Expand]Data Shaping
   [Expand]Examples
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Lesson 2 - Connect a Document to Data

This tutorial describes the steps required to connect a Snap document to data and provide a document data source with a master-detail relation. To start this tutorial, run the Snap application created in Lesson 1 - Create a Snap Application.

The tutorial consists of the following sections.

Expanded Connect to Data

This tutorial uses a connection to the sample Northwind database (the nwind.mdb file included in the product installation located by default at C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data).

To connect a Snap report to data, do the following.

Click Data | Add New Data Source on the Snap application's ribbon toolbar.

Alternatively, right-click an empty area in the Data Explorer and click Add Data Source in the invoked menu.

The Data Source Wizard is invoked. Proceed with the following steps in the wizard.

  1. On the first page of the invoked Data Source wizard, specify a name for the new data source and click Next.

  2. On the next page, select a data source type (Database) and click Next.

  3. If a data connection has already been specified in the application, the next wizard page allows you to select whether to use one of the existing connections, or create a new one.

  4. On the next page, select a data provider, specify the required connection settings and click Next.

    Select from the following supported data source types.

    Relational Database System

    Supported Versions

    .NET Framework Data Provider

    .NET Standard 2.0 Data Provider

    Microsoft SQL Server

    2005 or higher

    2005 Express or higher

    Azure SQL Database

    System.Data.SqlClient.dll

    System.Data.dll (Included in .NET Framework)

    System.Data.SqlClient.dll

    Microsoft Access

    Access 2000 or higher

    Access 2007 or higher

    System.Data.dll (Included in .NET Framework)

     

    Microsoft SQL Server CE

    3.5, 4.0

    System.Data.SqlServerCe.dll (Included in .NET Framework)

     

    Oracle Database

    9i or higher

    Oracle.ManagedDataAccess.dll

    System.Data.OracleClient.dll

    Oracle.DataAccess.dll

    Oracle.ManagedDataAccess.Core.dll

    Amazon Redshift

    n/a

    Npgsql.dll

    Npgsql.dll

    Google BigQuery

    Only legacy SQL functions and operations are supported

    DevExpress.DataAccess.BigQuery.dll

    DevExpress.DataAccess.BigQuery.dll

    Teradata

    13.0 or higher

    Teradata.Client.Provider.dll

    Teradata.Client.Provider.dll

    SAP Sybase Advantage

    Advantage Database Server 9.1 or higher

    Advantage.Data.Provider.dll

     

    SAP Sybase ASE

    Sybase Adaptive Server 12.0 or higher

    Sybase.AdoNet4.AseClient.dll

     

    SAP SQL Anywhere

    11 or higher

    Sap.Data.SQLAnywhere.dll

     

    IBM DB2

    9.5 or higher

    IBM.Data.DB2.dll

    IBM.Data.DB2.Core.dll

    Firebird

    1.5 or higher, Dialect 3

    FirebirdSql.Data.FirebirdClient.dll

    FirebirdSql.Data.Firebird.dll

    FirebirdSql.Data.FirebirdClient.dll

    MySQL

    4.1 or higher

    MySql.Data.dll

    MySql.Data.dll

    Pervasive PSQL

    9.x or higher

    Pervasive.Data.SqlClient.dll

     

    PostgreSQL

    7.x or higher

    Npgsql.dll

    Npgsql.dll

    VistaDB

    4, 5

    VistaDB.5.NET40.dll

     

    SQLite

    3.x

    System.Data.SQLite.dll

    Microsoft.Data.SQLite.dll

    System.Data.SQLite.Core.dll

    Microsoft.Data.Sqlite.Core.dll

    XML file

    n/a

    Built-in support

    Built-in support

    Depending on the selected data provider, it may be necessary to specify additional connection options (such as authentication type and database name) on this page.

    Alternatively, you can select Custom connection string and specify the connection string.

    Use the XpoProvider parameter to identify a data source provider. See connection string examples in the table below.

    Relational Database System

    Connection String Sample <sup>See Note</sup>

    Microsoft SQL Server <sup>*</sup>

    XpoProvider=MSSqlServer;Data Source=(local);User ID=username;Password=password;Initial Catalog=database;Persist Security Info=true

    <sup>*</sup>The MS SQL Server data provider is automatically specified if you set the "Initial Catalog" parameter and do not use the word "Provider" (for instance, the "XpoProvider" parameter) in the connection string.

    Microsoft Access

    XpoProvider=MSAccess;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

    XpoProvider=MSAccess;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\mydatabase.accdb;User Id=admin;Password=;

    Microsoft SQL Server CE

    XpoProvider=MSSqlServerCE;Data Source=MyDatabase.sdf;Password=MyPassword

    Oracle Database

    XpoProvider=Oracle;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

    XpoProvider=ODP;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

    XpoProvider=ODPManaged;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

    Amazon Redshift

    XpoProvider=Amazon Redshift;Server=127.0.0.1;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Encoding=UNICODE

    Google BigQuery

    XpoProvider=BigQuery;ProjectID=myProject;DataSetId=myDataSet;OAuthClientId=myClientId;OAuthClientSecret=mySecret;OAuthRefreshToken=myRefreshToken

    XpoProvider=BigQuery;ProjectId=project;DatasetId=dataset;ServiceAccountEmail=example@gmail.com;PrivateKeyFileName=key.p12

    Teradata

    XpoProvider=Teradata;Data Source=myServerAddress;User ID=myUsername;Password=myPassword;

    SAP Sybase Advantage

    XpoProvider=Advantage;Data Source=\myserver\myvolume\mypat\mydd.add;ServerType=local;User ID=ASSSYS;TrimTrailingSpaces=true

    SAP Sybase ASE

    XpoProvider=Ase;Port=5000;Data Source=MyAseServer;User ID=MyUserName;Password=MyPassword;Initial Catalog=MyDatabase;Persist Security Info=true

    SAP SQL Anywhere

    XpoProvider=Asa;eng=server;uid=user;pwd=password;dbn=database;persist security info=true;

    IBM DB2

    XpoProvider=DB2;Server=server:port;Database=database;UID=user;PWD=password;

    Firebird

    XpoProvider=Firebird;DataSource=localhost;User=SYSDBA;Password=masterkey;Database=MyDatabase.fdb;ServerType=0;Charset=NONE

    MySQL

    XpoProvider=MySql;Server=MyServerAddress;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Persist Security Info= true;Charset=utf8

    Pervasive PSQL

    XpoProvider=Pervasive;Server=MyServerAddress;UID=MyUserName;PWD=MyPassword;ServerDSN=MyDatabase

    PostgreSQL

    XpoProvider=Postgres;Server=127.0.0.1;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Encoding=UNICODE

    VistaDB

    XpoProvider=VistaDB;Data Source=C:\mydatabase.vdb4

    XpoProvider=VistaDB5;Data Source=C:\mydatabase.vdb5

    SQLite

    XpoProvider=SQLite;Data Source=filename

    XML file

    XpoProvider=InMemoryDataStore;data source=D:\Contacts.xml;read only=True

    Note

    The connection strings demonstrated above are examples. You can specify alternative variants.

    To proceed to the next wizard page, click Next.

  5. On the next page, you are prompted to save the connection string including or excluding the user name and a password. Choose any option and click Next.
  6. This page allows you to select a query or a stored procedure.

    Click Run Query Builder... to invoke the Query Builder window.

    Important

    Manual SQL editing is not allowed by default. Enabling custom SQL queries may lead to inadvertent or unauthorized modifications to your data/database structure. Before you decide to allow manual SQL editing, we recommend you to follow best practices and implement the appropriate end-user read/write permissions at the database level.

    If for some reason you have to enable custom SQL editing, set the SnapControl.Options.DataSourceWizardOptions.SqlWizardSettings.EnableCustomSql option to true.

    Note that only SELECT statements are allowed in the text. To override this restriction, handle the SnapControl.ValidateCustomSql event.

  7. In the invoked Query Builder window, double-click the Categories item in the list of available tables on the left to add it to the tables included into the query.

    Enable the check box for the Categories table, to include all of its fields in the view.

    Click OK to close the Query Builder and return to the Data Source Wizard.

  8. When the query is ready, click Finish to save it.

After the data source has been added to the report, its data members and data fields are displayed in the Data Explorer.

Expanded Create a Master-Detail Relation

This section of the tutorial illustrates how to add a master-detail relation to the document's data source.

  1. Right-click the NWind Data Source node in the Data Explorer window and select Manage Queries... in the invoked context menu.

  2. The Manage Queries dialog is displayed. It lists the available queries and allows you to edit them, delete or add a new query. Click the ellipsis to the right of the query name to invoke the Query Editor dialog for the selected query.

  3. Click Run Query Builder.. to invoke the Query Builder window.

  4. Double-click the Products item in the list of available tables on the left to include it in the list of data tables to be used.

    Enable the check box for the Products table, to include all of its fields in the view.

    Click OK to close the Query Builder. Click Finish to close the Query Editor. Click OK to close the Manage Queries window which contains now two queries.

  5. Right-click the NWind Data Source node in the Data Explorer window and select Manage Relations... in the invoked context menu.

  6. In the invoked Master-Detail Relation Editor window select the CategoryID item in the Categories table and drag it to item of the same name in the Products table.

  7. The relation is created as illustrated in the following image.

    Next, click OK to apply changes to the data source and exit.

  8. The content of the Data Explorer will be updated to reflect the new structure of the document data source.

To create a detail report, drag-and-drop the ProductName, UnitPrice and UnitsOnOrder fields of the CategoriesProducts relation from the Data Explorer onto the document's body, as shown in the image below.

The master-detail report is now ready. Click the Print Preview button in the File tab of the ribbon menu to view the preview.

Expanded See Also

Is this topic helpful?​​​​​​​