excell to dataset to datagrid

W

WStoreyII

i got this code straight out of the msdn but it is not working i get in an
exception when it tries to fill the dataset what is wrong?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

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 9.0;")

' Select the data from Sheet1 of the workbook.

MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from
[Sheet1$]", MyConnection)

DS = New System.Data.DataSet("DS")

MyCommand.Fill(DS)

DataGrid1.DataSource = DS

MyConnection.Close()

End Sub



Thanks for the help

WStoreyII
 
B

Bill McCarthy

Hi WStorey,

try changing the extended property from 9.0 to 8.0, eg:

System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " &
"data source=C:\myData.XLS; " & "Extended Properties=Excel 8.0;")



Bill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top