彩票走势图

Spread Studio for .NET使用教程:将复合框绑定到DataReader

原创|使用教程|编辑:郝浩|2013-05-10 10:35:37.000|阅读 199 次

概述:你可以将组合框绑定到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@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP