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.v23.1.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:
- Bind Reports to Data
- Create a Master-Detail Report with a Detail Report Band
- Manage Data Sources at Runtime
Example
The following code example illustrates how to bind a report to the Northwind database’s Products table and display product names:
#region #reference
using System.Windows.Forms;
using System;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...
#endregion #reference
namespace RuntimeBindingToMdbDatabase {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
#region #code
private SqlDataSource BindToData() {
// Create a data source with the specified connection parameters.
Access97ConnectionParameters connectionParameters =
new Access97ConnectionParameters("../../nwind.mdb", "", "");
SqlDataSource ds = new SqlDataSource(connectionParameters);
// Create an SQL query to access the Products table.
CustomSqlQuery query = new CustomSqlQuery();
query.Name = "customQuery";
query.Sql = "SELECT * FROM Products";
// Add the query to the collection.
ds.Queries.Add(query);
// Update the data source schema.
ds.RebuildResultSchema();
return ds;
}
private XtraReport CreateReport() {
// Create a new report instance.
XtraReport report = new XtraReport();
// Assign the data source to the report.
report.DataSource = BindToData();
report.DataMember = "customQuery";
// 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 label to the data, dependent on the data binding mode.
if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings)
label.DataBindings.Add("Text", null, "customQuery.ProductName");
else
label.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
// Add the label to the detail band.
detailBand.Controls.Add(label);
return report;
}
private void button1_Click(object sender, EventArgs e) {
// Invoke the report preview.
ReportPrintTool printTool = new ReportPrintTool(CreateReport());
printTool.ShowPreview();
}
private void button2_Click(object sender, EventArgs e) {
// Invoke the End-User Designer and load the report.
ReportDesignTool designTool = new ReportDesignTool(CreateReport());
designTool.ShowRibbonDesignerDialog();
}
#endregion #code
}
}
Related GitHub Examples
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.