Skip to main content
A newer version of this page is available. .

XtraReportBase.DataMember Property

Specifies the collection, list, or table in the object assigned to the DataSource property from which to retrieve the data.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v21.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[DefaultValue("")]
[SRCategory(ReportStringId.CatData)]
public string DataMember { get; set; }

Property Value

Type Default Description
String String.Empty

The name of the collection, list, or table in the data source.

Remarks

The DataMember property specifies the collection/list in the object assigned to the report data source from which to retrieve the data.

As a general rule, when you bind a report to the database, you must specify the table name as the DataMember property value. A JSON source may have multiple data sets, all owned by the topmost root element. In this situation, you must specify the DataMember as the name of the JSON data set under the root node.

You can omit the DataMember property in some cases, such as when the object assigned to the DataSource property is a collection or list.

When you change the report data source, the DataMember property is reset, and you must explicitly specify the DataMember value. It is necessary when you use the DataSourceManager.ReplaceDataSource method to replace the data source bound to the report elements.

Review the following topics for more information:

Example

The following code example illustrates how to bind a report to the Northwind database’s Products table and display product names:

using System.Windows.Forms;
using System;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.XtraReports.UI;

// ...
private SqlDataSource BindToData() {
    // Create a data source that retrieves data from an XML file.  
    XmlFileConnectionParameters connectionParameters =
        new XmlFileConnectionParameters(@"C:\Users\Public\Documents\DevExpress Demos 21.2\Components\Data\nwind.xml");
    SqlDataSource dataSource = new SqlDataSource(connectionParameters);

    // Build a query that retrieves product names.
    SelectQuery query = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectColumn("ProductName")
        .Build("Products");

    // Add this query to the data source.
    dataSource.Queries.Add(query);

    // Populate the data source with data.
    dataSource.Fill();

    return dataSource;
}

private XtraReport CreateReport() {
    // Create a new report instance.
    XtraReport report = new XtraReport();

    // Assign a data source to the created report.
    report.DataSource = BindToData();
    report.DataMember = "Products";

    // Add a detail band to the report.
    DetailBand detailBand = new DetailBand();
    detailBand.Height = 50;
    report.Bands.Add(detailBand);

    // Create a new label.
    XRLabel label = new XRLabel { WidthF = 300 };
    // Bind the created label to the ProductName data field.
    label.ExpressionBindings.Add(new ExpressionBinding("Text", "[ProductName]"));
    // Add the label to the detail band.
    detailBand.Controls.Add(label);

            return report;
}

private void exportButton_Click(object sender, EventArgs e) {
    // Export the report to DOCX and save the exported file to the application folder.
    XtraReport report = CreateReport();
    report.ExportToDocx(report.Name + ".docx");
}

private void printButton_Click(object sender, EventArgs e) {
    // Send the report to the default printer.
    XtraReport report = CreateReport();
    report.Print();
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataMember property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Implements

See Also