下面的示例演示了如何在运行时刻创建新空白报表 (XtraReport 类的实例),如何创建被绑定到 MDB 文件的数据对象 (通过 XtraReportBase.DataSource、XtraReportBase.DataAdapter 和 XtraReportBase.DataMember 属性),然后填充报表的 DetailBand(细节带区),此带区包含一个显示 MDB 文件中数据的 XRLabel 报表控件。
| C# |  复制代码 | 
|---|
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
private void button1_Click(object sender, EventArgs e) {
    
    XtraReport report = new XtraReport();
    
    OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Categories",
        @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\nwind.mdb");
    DataSet ds = new DataSet();
    adapter.FillSchema(ds, SchemaType.Source);
    
    report.DataSource = ds;
    report.DataAdapter = adapter;
    report.DataMember = "Table";
    
    
    DetailBand detailBand = new DetailBand();
    detailBand.Height = 50;
    report.Bands.Add(detailBand);
    
    XRLabel label = new XRLabel();
    label.DataBindings.Add("Text", null, "CategoryName");
    detailBand.Controls.Add(label);
    
    report.ShowPreview();
}
 | 
 
| Visual Basic |  复制代码 | 
|---|
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
    
    Dim report As New XtraReport()
    
    Dim adapter As New OleDbDataAdapter("SELECT * FROM Categories", _
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\nwind.mdb")
    Dim ds As New DataSet()
    adapter.FillSchema(ds, SchemaType.Source)
    
    report.DataSource = ds
    report.DataAdapter = adapter
    report.DataMember = "Table"
    
    Dim detailBand As New DetailBand()
    detailBand.Height = 50
    report.Bands.Add(detailBand)
    
    Dim label As New XRLabel()
    label.DataBindings.Add("Text", Nothing, "CategoryName")
    detailBand.Controls.Add(label)
    
    report.ShowPreview()
End Sub
 | 
 
参阅