我有一个使用VB.NET和Access数据库的项目桌面应用程序。客户向我请求,以便他们可以从Excel导入数据客户访问数据库。但它包含一些错误。
这会将数据从Excel导入到访问数据库:
Sub import()
DeleteTable()
Dim i As Integer
'looping from excel data
For i = 0 To (objDataTableExcel.Rows.Count - 1)
Try
'show data it's save from some coloumn
With objDataTableExcel.Rows(i)
Field1 = .Item(0)
Field2 = .Item(1)
Field3 = .Item(2)
End With 'input from variable to table
strSQL = "Insert Into " & "[" & Trim(txtTable.Text) & "]" & "(ID , Name , Number) Values " & _
" (" & Field1 & ",'" & Field2 & "' ,'" & Field3 & "'); "
objCommand = New OleDbCommand
objCommand.Connection = MyConnection.open
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSQL
objDataAdapter = New OleDbDataAdapter(objCommand)
objDataAdapter.Fill(objDataSet, "hal_Import")
MyConnection.close()
Catch ex As Exception
'When Err.Number <> 0
'MsgBox("can't connect to database" & vbCrLf & Err.Description)
MsgBox(ex.ToString)
Exit Sub
End Try
Next i
MsgBox("Import Finish", MsgBoxStyle.Information, "Import Data")
End Sub
并且Excel和访问数据库的连接是另一种方法。错误显示连接是溢出并且此错误: