有没有办法从 MS Access 数据库中获取记录,并将它们存储在单个数组中?
如果更容易,我也愿意接受有关如何以另一种方式做到这一点的任何建议。
问问题
367 次
1 回答
1
由于数组具有静态大小,因此我决定改用字符串列表,因为数据库中除主键外的所有字段类型都设置为 Text。我的代码如下(以防万一):
Imports System.Data.OleDb
Dim dbConnection As OleDbConnection
Dim dbCommand As OleDbCommand
Dim dbReader As OleDbDataReader
Dim sqlString As String
Dim path As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=" & _
Server.MapPath("database.accdb")
Dim lstRecords As List(Of String)
Sub page_load()
lstRecords = New List(Of String)
Try
dbConnection = New OleDbConnection(path)
dbConnection.Open()
sqlString = "SELECT * FROM table"
dbCommand = New OleDbCommand(sqlString, dbConnection)
dbReader = dbCommand.ExecuteReader()
While dbReader.Read()
lstRecords.Add(dbReader("record1") + "," + dbReader("record2"))
End While
dbReader.Close()
Finally
dbConnection.Close()
End Try
End Sub
于 2013-11-07T05:36:56.517 回答