原創|使用教程|編輯:郝浩|2013-05-10 10:35:37.000|閱讀 253 次
概述:你可以將組合框綁定到DataReader。DataReader允許用戶以只讀的形式訪問數據源中的數據。使用DataReader通常是一個快速返回結果的方法,下面是詳細的代碼示例。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在Spread Studio for .NET中你可以將組合框綁定到DataReader。DataReader允許用戶以只讀的形式訪問數據源中的數據。使用DataReader通常是一個快速返回結果的方法,下面是詳細的代碼示例:
》》》免費下載Spread Studio for .NET最新版
C#
/// Set up a connection to the database.
string dbpath = "c:\\reader.mdb";
System.Data.OleDb.OleDbConnection dbConn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + dbpath);
/// Open a connection and a SELECT command.
dbConn.Open();
System.Data.OleDb.OleDbCommand dbCommand = new System.Data.OleDb.OleDbCommand("SELECT * FROM Table1", dbConn);
/// Open a DataReader on that connection and command.
System.Data.OleDb.OleDbDataReader dr = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
/// Loop through the rows returned by the reader.
ArrayList al = new ArrayList();
while (dr.Read()) {
al.Add(dr("Data"));
}
/// Populate combo box with data converted to strings.
string[] s;
s = al.ToArray(typeof(string));
FarPoint.Win.Spread.ComboBoxCellType cb = new FarPoint.Win.Spread.ComboBoxCellType();
cb.Items = s;
FpSpread1.ActiveSheetView.Cells(0, 0).CellType = cb;
/// Dispose connection.
dbConn.Dispose();
VB
' Set up a connection to the database.
Dim dbpath As String = "c:\reader.mdb"
Dim dbConn As New System.Data.OleDb.OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbpath)
' Open a connection and a SELECT command.
dbConn.Open()
Dim dbCommand As New System.Data.OleDb.OleDbCommand( _
"SELECT * FROM Table1", dbConn)
' Open a DataReader on that connection and command.
Dim dr As System.Data.OleDb.OleDbDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
' Loop through the rows returned by the reader.
Dim al As New ArrayList()
While dr.Read()
al.Add(dr("Data"))
End While
' Populate combo box with data converted to strings.
Dim s As String()
s = al.ToArray(GetType(String))
Dim cb As New FarPoint.Win.Spread.ComboBoxCellType
cb.Items = s
FpSpread1.ActiveSheetView.Cells(0, 0).CellType = cb
' Dispose connection.
dbConn.Dispose()
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都控件網