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?

Recommended Answers

All 2 Replies

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.