Skip to main content

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.v24.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 sample creates a new SqlDataSource, creates a report with the XRTable control at runtime, and binds the table to data:

Table Report in Code

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
// ...
private static XtraReport CreateReport()
{
    // Creates a new data source.
    SqlDataSource sqlDataSource = CreateSQLDataSource();

    // Creates a new report and assigns the data source.
    XtraReport report = new XtraReport();
    report.DataSource = sqlDataSource;
    report.DataMember = "selectQuery";

    // Creates a detail band and adds it to the report.
    DetailBand detailBand = new DetailBand();
    report.Bands.Add(detailBand);

    // Creates a table and adds it to the detail band.
    XRTable table = new XRTable();
    detailBand.Controls.Add(table);

    // Creates a row and adds the product name and product price cells to the row.
    table.BeginInit();

    XRTableRow row = new XRTableRow();
    table.Rows.Add(row);

    XRTableCell productName = new XRTableCell();
    XRTableCell productPrice = new XRTableCell();

    row.Cells.Add(productName);
    row.Cells.Add(productPrice);

    // Binds the table cells to the data fields.
    productName.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
    productPrice.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]"));

    // Adjust the table width.
    table.BeforePrint += Table_BeforePrint;

    table.EndInit();
    return report;
}

private static void Table_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
    XtraReport report = (sender as XRTable).RootReport;
    (sender as XRTable).WidthF = report.PageWidth - report.Margins.Left - report.Margins.Right;
}
private static SqlDataSource CreateSQLDataSource()
{
    // Creates a data source. 
    SQLiteConnectionParameters connectionParameters = new SQLiteConnectionParameters("Data/nwind.db", "");
    SqlDataSource dataSource = new SqlDataSource(connectionParameters);

    // Creates a SELECT query.
    SelectQuery query = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectColumn("ProductName")
        .SelectColumn("UnitPrice")
        .Build("selectQuery");

    // Adds the query to the collection and returns the data source. 
    dataSource.Queries.Add(query);
    dataSource.Fill();
    return dataSource;
}

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.

See Also