Back to Devexpress

Bind a Report to a Data Source Schema

xtrareports-4797-feature-guide-to-devexpress-reports-bind-reports-to-data-sql-database-bind-a-report-to-a-data-source-schema.md

latest7.5 KB
Original Source

Bind a Report to a Data Source Schema

  • Feb 18, 2026
  • 4 minutes to read

This tutorial demonstrates how to bind a report to a data source schema and supply data at runtime. Use this technique if the report’s data source is unavailable at design time.

Note

When a report is bound to an XML file, you cannot use the following data-shaping capabilities at the data source level:

  • Sort, group and filter data
  • Aggregate functions

Create a Data Source Schema

Use the WriteXmlSchema method to create an XSD file that contains a data source schema. Refer to the Create and configure datasets in Visual Studio documentation topic for more information.

The following code writes the XSD schema to a file:

csharp
nwindDataSet ds = new nwindDataSet();
ds.WriteXmlSchema(@"C:/Temp/1.xsd");
vb
Dim ds As New nwindDataSet()
ds.WriteXmlSchema("C:/Temp/1.xsd")

Use the XSD file as a data source schema for a new report. The following example contains the XML schema for the Products table from the sample Northwind database:

xml
<?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>

Assign the Data Source Schema at Design Time

  1. Start Microsoft Visual Studio and create a new application, or open an existing application.

  2. Add a new blank report to it.

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

  4. In the invoked Data Source Wizard, select XML file and click Next.

  5. On the next page, select the first option to create a new data connection. Click Next.

  6. Specify the path to the database schema file. Click Next.

  7. Click Next to save the connection string to the configuration file.

  8. On the next page, you can choose which tables, views, and/or stored procedures to add to the report. To construct custom queries, use the Query Builder.

Obtain the Data and View the Result

At runtime, create (or get) an instance of the data source. This data source should have the same type that you specified for the schema at design time.

csharp
private void button1_Click(object sender, EventArgs e) {
    // Obtain a dataset or create a new one.
    // For example:
    nwindDataSet ds = new nwindDataSet();
    new nwindDataSetTableAdapters.ProductsTableAdapter().Fill(ds.Products);

    // Create a report and bind it to a dataset.
    XtraReport1 report = new XtraReport1();
    report.DataSource = ds;

    // Show the print preview.
    ReportPrintTool pt = new ReportPrintTool(report);
    pt.ShowPreview();
}
vb
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
    ' Obtain a dataset or create a new one.
    ' For example:
    Dim ds As New nwindDataSet()
    CType(New nwindDataSetTableAdapters.ProductsTableAdapter(), _
        nwindDataSetTableAdapters.ProductsTableAdapter).Fill(ds.Products)

    ' Create a report and bind it to a dataset.
    Dim report As New XtraReport1()
    report.DataSource = ds

    ' Show the print preview.
    Dim pt As New ReportPrintTool(report)
    pt.ShowPreview()
End Sub

The report is bound to data. Run the print preview form to view the result.

See Also

Bind a Report to a List Object at Design Time and Supply Data at Runtime

DataSourceSchema