问题描述
- vbnet连接数据库问题:导出二维数组,JEt正常,换成ACE后出错,
-
代码如下:一个按钮,一个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:UsersLPHDownloadsDesktopH型钢数据库.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
解决方案
ADO是早期的库,不支持ace驱动,你得用ADO.NET去连,也就是system.data.oledb
解决方案二:
你的代码虽然名义上是vb.net的,但是还是用的是vb6的那一套。
解决方案三:
谢谢,采用ADO.net很容易就解决了64位下的数据库操作。
iRow = MyDataTable.Rows.Count
iLie = MyDataTable.Columns.Count
ReDim MyArray(iRow - 1, iLie - 1)
For i = 0 To iRow - 1
For j = 0 To iLie - 1
MyArray(i, j) = MyDataTable.Rows(i).Item(j)
Next
Next
时间: 2024-10-27 19:39:34