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?