F
funcSter
I want to retrieve data from an Excel file like how I would with a
database. I understand that I would have to use OLE DB. Somehow I
think I cannot get the connection string right, as the bit of code
fails at "objConn.Open()" with the error:
System.Data.OleDb.OleDbException: Could not find installable ISAM.
Can somebody please help me out? I'm still a learning programmer, so
if someone can point out my mistakes, it'll be great! Thanks!
Dim objConn As OleDbConnection
Dim objTrans As OleDbTransaction
Dim objCmd As OleDbCommand
Dim objRead As OleDbDataReader
Dim strSource As String = "C:\temp\data.xls"
Dim strConn As String = "Persist Security Info=False;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + strSource + ";" & _
"Extended Properties=Microsoft Excel 97-2000;"
objConn = New OleDb.OleDbConnection(strConn)
objConn.Open()
Dim strSQLQuery As String = "SELECT * FROM [Sheet1$]"
objCmd.CommandText = strSQLQuery
objRead = objCmd.ExecuteReader()
While objRead.Read()
' Manipulate data
End While
objTrans.Commit()
objConn.Close()
objConn = Nothing
database. I understand that I would have to use OLE DB. Somehow I
think I cannot get the connection string right, as the bit of code
fails at "objConn.Open()" with the error:
System.Data.OleDb.OleDbException: Could not find installable ISAM.
Can somebody please help me out? I'm still a learning programmer, so
if someone can point out my mistakes, it'll be great! Thanks!
Dim objConn As OleDbConnection
Dim objTrans As OleDbTransaction
Dim objCmd As OleDbCommand
Dim objRead As OleDbDataReader
Dim strSource As String = "C:\temp\data.xls"
Dim strConn As String = "Persist Security Info=False;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + strSource + ";" & _
"Extended Properties=Microsoft Excel 97-2000;"
objConn = New OleDb.OleDbConnection(strConn)
objConn.Open()
Dim strSQLQuery As String = "SELECT * FROM [Sheet1$]"
objCmd.CommandText = strSQLQuery
objRead = objCmd.ExecuteReader()
While objRead.Read()
' Manipulate data
End While
objTrans.Commit()
objConn.Close()
objConn = Nothing