本示例会向您演示如何在运行时将数据感知控件(XtraGrid、XtraPivotGrid、XtraVerticalGrid等)绑定到数据库。请注意,在将控件绑定到数据源之后,可能需要针对具体控件进行额外的自定义。更多相关信息,请参阅相应控件的文档。
以下代码演示了如何将GridControl绑定到NWind数据库的Products表。
[C#]
using System.Data.OleDb; // ... // Create a connection object. OleDbConnection connection = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\DBs\\NWIND.MDB"); // Create a data adapter. OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Products", connection); // Create and fill a dataset. DataSet sourceDataSet = new DataSet(); adapter.Fill(sourceDataSet); // Specify the data source for the grid control. gridControl1.DataSource = sourceDataSet.Tables[0];
[VB]
Imports System.Data.OleDb ' ... ' Create a connection object. Dim Connection As New OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\DBs\\NWIND.MDB") ' Create a data adapter. Dim Adapter As New OleDbDataAdapter("SELECT * FROM Products", Connection) ' Create and fill a dataset. Dim SourceDataSet As New DataSet() Adapter.Fill(SourceDataSet) ' Specify the data source for the grid control. GridControl1.DataSource = SourceDataSet.Tables(0)
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/913.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/913.html