Hi,
A piece of simple code to import excel file to a database, as shown below, I have problem when I tried to open the connection, the error message shows Excel driver is not correct. where shall I get the correct driver string? thanks.
Private Sub OpenExcelFile_F ileOk(ByVal sender As System.Object, ByVal e As System.Componen tModel.CancelEv entArgs) Handles OpenExcelFile.F ileOk
Name = OpenExcelFile.F ileName
Dim ConnectionStrin g As String = _
"Drive = {Microsoft Excel Driver (*.xls)};Driver ID=790;" & "Dbq=" & Name
Dim con As New Odbc.OdbcConnec tion(Connection String)
Dim cmdSelect As New Odbc.OdbcComman d("SELECT * FROM [Sheet1$]", con)
Dim adapter As New Odbc.OdbcDataAd apter(cmdSelect )
Dim ds As New DataSet
Try
con.Open() 'problem here, excel driver error
adapter.Fill(ds , "Sheet1")
Catch ex As Exception
MsgBox(ex.ToStr ing)
Finally
con.Close()
End Try
EmployeeDataGri dView.DataSourc e = ds.Tables("Shee t")
End Sub
A piece of simple code to import excel file to a database, as shown below, I have problem when I tried to open the connection, the error message shows Excel driver is not correct. where shall I get the correct driver string? thanks.
Private Sub OpenExcelFile_F ileOk(ByVal sender As System.Object, ByVal e As System.Componen tModel.CancelEv entArgs) Handles OpenExcelFile.F ileOk
Name = OpenExcelFile.F ileName
Dim ConnectionStrin g As String = _
"Drive = {Microsoft Excel Driver (*.xls)};Driver ID=790;" & "Dbq=" & Name
Dim con As New Odbc.OdbcConnec tion(Connection String)
Dim cmdSelect As New Odbc.OdbcComman d("SELECT * FROM [Sheet1$]", con)
Dim adapter As New Odbc.OdbcDataAd apter(cmdSelect )
Dim ds As New DataSet
Try
con.Open() 'problem here, excel driver error
adapter.Fill(ds , "Sheet1")
Catch ex As Exception
MsgBox(ex.ToStr ing)
Finally
con.Close()
End Try
EmployeeDataGri dView.DataSourc e = ds.Tables("Shee t")
End Sub
Comment