0

I am working on exporting some data to a DataGrid (with no luck). So far I have:

Private Sub SaveDoc()

        Dim MyConn As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

        Try
            MyConn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='c:\book2.xls'; Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet]", MyConn)
            MyCommand.TableMappings.Add("Table", "TestTable")
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            DataGridView1.DataSource = DtSet.Tables(0)
            MyConn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try
    End Sub

When this runs, I get an error message that says:

System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet'. Make sure the object exists and that you spell its name and the path name correctly.

The excel file has only one sheet that is named "Sheet", and the location specified in the connection line is correct. Any ideas on why this may be happening?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by bklynman01
0

I changed select * from [sheet] to select * from [sheet1$] but this did not help. I still receive the same message:

System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.

I have also tried "Sheet 1" and "Sheet1" and "Sheet$1" and "". The only difference between all of these is the error message.

I looked at the other thread. Thank you for the reference. I'm not familiar with C# but I know enough about syntax to try and weed through it.

Any ideas on the problem at hand?

Edited by bklynman01: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.