Link to home
Start Free TrialLog in
Avatar of xiaohui
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.OleDbException' occurred in system.data.dll"

-----------------------------------------------------------------------
Dim DS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection

MyConnection = New System.Data.OleDb.OleDbConnection( _
      "provider=Microsoft.Jet.OLEDB.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.OleDbDataAdapter( _
      "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..

Avatar of prakash_prk
prakash_prk
Flag of India image

call  MyConnection.Open()
before fill the adapter

regards
prakash
ASKER CERTIFIED SOLUTION
Avatar of prakash_prk
prakash_prk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial