我正在尝试编写一些执行以下操作的代码:
问题来自点否。 3,因为Rows的索引不起作用,它总是显示第1行的数据(实际上,第0行是正确计数的)。我很想纠正它。
以下是执行此类操作的代码部分:
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " & "data source='" & h.FileName & " '; " & "Extended Properties=Excel 12.0;")
MyConnection.Open()
Dim tables As DataTable = MyConnection.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
MyConnection.Close()
hoja = ""
For i = 0 To tables.Rows.Count - 1
hoja = tables.Rows(i).Item("Table_Name").ToString
If hoja.Substring(Len(hoja) - 1, 1) = "$" Then
i = tables.Rows.Count - 1
Else
If hoja.Substring(Len(hoja) - 2, 1) = "$" Then
i = tables.Rows.Count - 1
End If
End If
Next
'Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & hoja & "]", MyConnection)
Dim dsds As New System.Data.DataSet
MyCommand.Fill(dsds)
MyConnection.Close()
MyConnection.Dispose()
MyConnection = Nothing
rma2.Text = dsds.Tables(0).Rows(1).Item(2)
Dim valsat As String
valsat = dsds.Tables(0).Rows(1).Item(8)
If (dsds.Tables(0).Rows(1).Item(19) Is "-1") Then
approval.Text = dsds.Tables(0).Rows(1).Item(45)
End If
obser.Text = dsds.Tables(0).Rows(2).Item(45)
model.Text = dsds.Tables(0).Rows(1).Item(16)
bfme.PerformClick()
peso.Text = "10"
bultos.Text = "1"