xiaohui
asked on
Read data from Excel file
I need to read from a Excel file and display the cell data on a form. I read helpfile and found out things like DataSet, DataAdapter, OleDbConnection, OleDbDataAdapter. I am very confused and really need some advice here.
I copied the below coding but encounters error
"An unhandled exception of type 'System.Data.OleDb.OleDbEx ception' occurred in system.data.dll"
-------------------------- ---------- ---------- ---------- ---------- -----
Dim DS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDat aAdapter
Dim MyConnection As System.Data.OleDb.OleDbCon nection
MyConnection = New System.Data.OleDb.OleDbCon nection( _
"provider=Microsoft.Jet.OL EDB.4.0; " & _
"data source=C:\myData.XLS; " & _
"Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDat aAdapter( _
"select * from [Sheet1$]", MyConnection)
DS = New System.Data.DataSet()
MyCommand.Fill(DS)
MyConnection.Close()
-------------------------- ---------- ---------- ---------- ---------- -----
I have no idea what to put for "provider=??"
I didnt use FileOpen because it is said that it will cause file corruption and loss of file integrity.
Please help..
I copied the below coding but encounters error
"An unhandled exception of type 'System.Data.OleDb.OleDbEx
--------------------------
Dim DS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDat
Dim MyConnection As System.Data.OleDb.OleDbCon
MyConnection = New System.Data.OleDb.OleDbCon
"provider=Microsoft.Jet.OL
"data source=C:\myData.XLS; " & _
"Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDat
"select * from [Sheet1$]", MyConnection)
DS = New System.Data.DataSet()
MyCommand.Fill(DS)
MyConnection.Close()
--------------------------
I have no idea what to put for "provider=??"
I didnt use FileOpen because it is said that it will cause file corruption and loss of file integrity.
Please help..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
before fill the adapter
regards
prakash