Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Collapse]Reporting
 [Expand]Product Information
 [Expand]Getting Started
 [Expand]Fundamental Concepts
 [Expand]Concepts
 [Expand]Design-Time Features
 [Collapse]Examples
  [Expand]Create a Report in Code
  [Expand]Add a Report to an Application
  [Expand]Design a Report
  [Collapse]Provide Data to a Report
   [Collapse]Connect a Report to Data
     How to: Bind a Report to a Database
     How to: Bind a Report to an MDB Database (Runtime Sample)
     How to: Bind a Report to an Entity Framework Data Source
     How to: Bind a Report to an Entity Framework Stored Procedure
     How to: Bind a Report to an MS SQL Server (Runtime Sample)
     How to: Bind a Report to a Stored Procedure
     How to: Bind a Report to an Array List
     How to: Bind a Report to a Collection that Implements the ITypedList Interface
     How to: Bind a Report to an XML File
     How to: Bind a Report to an XML File (Runtime Sample)
     How to: Bind a Report to Multiple Data Sources
     How to: Bind a Report to Multiple Data Tables
     How to: Provide Custom Names for Data Items in the Field List
     How to: Bind a Report to a Data Source Schema
     How to: Bind a Report to a List Object at Design Time and Provide Data at Runtime
     How to: Bind a Report to an Object Data Source
     How to: Bind a Report to an Excel Workbook
     How to: Bind a Report to a CSV File
     How to: Bind a Report to an Excel Workbook (Runtime Sample)
     How to: Bind a Report to a CSV File (Runtime Sample)
     How to: Register a Custom Schema Provider for a Synonym Database
   [Expand]Connect to Data in ASP.NET
   [Expand]Supply Data to a Report
   [Expand]Use Calculated Fields
   [Expand]Use Report Parameters
  [Expand]Shape Data in a Report
  [Expand]Provide Navigation for Large Reports
  [Expand]Add Interactivity to Documents in Print Preview
  [Expand]Use Charts, Grids and Custom Controls
  [Expand]Use Bar Codes
  [Expand]Add Details about a Report
  [Expand]Customize the Report Appearance
  [Expand]Publish Your Reports
  [Expand]Store Your Reports
  [Expand]Create an End-User Reporting Application
  End-User Capabilities
 [Expand]Localization
 [Expand]Redistribution and Deployment
 [Expand]API Reference
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Bind a Report to a Data Source Schema

This tutorial demonstrates how to bind a report to a data source schema and supply data at runtime. This approach is useful when the report's data source is not available at design time.

To bind a report to a data source schema, do the following.

Expanded Create a Data Source Schema

You can create an XSD file containing a schema of a data source, using the WriteXmlSchema method. For example:

The created XSD file now may be used as a data source schema for new reports. For example, if a data source contains the Products table from the sample Northwind database (nwind.mdb file, which is shipped with XtraReports installation), the XML schema will look as follows:

XSD
<?xml version="1.0" standalone="yes"?>
<xs:schema id="nwindDataSet" targetNamespace="http://tempuri.org/nwindDataSet.xsd"
xmlns:mstns="http://tempuri.org/nwindDataSet.xsd" xmlns="http://tempuri.org/nwindDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:element name="nwindDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Products">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="ProductID" msdata:AutoIncrement="true" type="xs:int" />
              <xs:element name="ProductName" minOccurs="0">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:maxLength value="40" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="SupplierID" type="xs:int" minOccurs="0" />
              <xs:element name="CategoryID" type="xs:int" minOccurs="0" />
              <xs:element name="QuantityPerUnit" minOccurs="0">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:maxLength value="20" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="UnitPrice" type="xs:decimal" minOccurs="0" />
              <xs:element name="UnitsInStock" type="xs:short" minOccurs="0" />
              <xs:element name="UnitsOnOrder" type="xs:short" minOccurs="0" />
              <xs:element name="ReorderLevel" type="xs:short" minOccurs="0" />
              <xs:element name="Discontinued" type="xs:boolean" minOccurs="0" />
              <xs:element name="EAN13" minOccurs="0">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:maxLength value="12" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:Products" />
      <xs:field xpath="mstns:ProductID" />
    </xs:unique>
  </xs:element>
</xs:schema>

Expanded Assign the Data Source Schema to a Report

  1. Start Microsoft Visual Studio 2010, 2012, 2013, 2015 or 2017 and create a new application under any of the supported platforms, or open an existing one.

  2. Add a new blank report to it.

  3. Click the report's smart tag. In the invoked actions list, expand the drop-down menu for the DataSource property and click Add Report Data Source...

  4. On the first page of the invoked Data Source Wizard, select Database and click Next.

  5. The next page allows you to specify whether you want to use an existing data connection or create a new data connection. Select "No, I'd like to specify the connection parameters myself" and click Next.

  6. On the next page, specify the data provider (XML file) and the path to the database schema file.

    To proceed to the next wizard page, click Next.

  7. Click Next on the following page to save the created connection string to the configuration file.

  8. On the next page, you can select a table, view or stored procedure or construct a custom query using the Query Builder.

    Note

    Some of the data shaping capabilities available to SQL data sources (such as sorting, grouping and filtering data, as well as using aggregate functions) are not supported for XML files.

    Click Finish in the Data Source Wizard to exit the wizard.

    The newly created SQL data source will be displayed in the Components node of the Report Explorer.

    You can see the data source structure in the Field List window.

    Drop the required fields onto the report's Detail band from the Field List, to create report controls bound to these fields.

Expanded Obtain the Data and View the Result

At runtime create (or get) an instance of the data source of the same type which was used in the data source schema at design time.

The report (along with its controls) is now bound to data. Run the print preview form, and view the result.

Expanded See Also

How would you rate this topic?​​​​​​​