代码如下:一个按钮,一个listbox,数据表导出二维数组,同时将数据表中的字段1显示在listbox中。
Public Class Form1
Dim con As New ADODB.Connection
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim SltSet As String = "H型钢"
Dim rs As New ADODB.Recordset
Dim ds As New DataSet
Dim iRow As Integer = 0
Dim iLie As Integer = 4
Dim MyArray(iRow, iLie) As Object
Dim connectionString As String = "provider=Microsoft.ACE.OLEDB.12.0;data source=" & "C:\Users\LPH\Downloads\Desktop\H型钢数据库.accdb"
Dim a As String = "select*from "
'Try
con.Open(connectionString)
SltSet = a & SltSet
rs.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs.LockType = ADODB.LockTypeEnum.adLockReadOnly
rs.ActiveConnection = con
rs.Open(SltSet, con)
iRow = rs.RecordCount
iLie = rs.Fields.Count
ReDim MyArray(iRow - 1, iLie - 1)
Dim i, j As Integer
For i = 0 To iRow - 1
For j = 0 To iLie - 1
MyArray(i, j) = rs(j).Value
Next
Next
For i = 0 To iRow - 1
ListBox1.Items.Add(MyArray(i, 0))
Next
End Sub
End Class