:?: Hi all
I'm trying to import data from an exel sheet to a data grid but I keep on getting the following error "The Microsoft Jet database engine could not find the object"

Here is my code

Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class ExellFrm

    Private Sub ExellFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim myPath As String = "C:\Users\John\Desktop\book1.xls"

            ' importing Data from Excel
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source='" & myPath & " '; " & "Extended Properties=Excel 8.0;")
            ' Select the data from Sheet of the workbook.
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [test$]", MyConnection)
            DtSet = New System.Data.DataSet
            exellgrid.DataSource = DtSet
        Catch ex As Exception
            MessageBox.Show("ERROR  " & ex.Message)
        End Try
    End Sub
End Class

>The Microsoft Jet database engine could not find the object

Don't seem any problem with your code. Have you found any solution?


Try something like this:

Dim theConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=book1.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;""")
Dim theDataAdapter As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", theConnection)
Dim theDS As New DataSet()
Dim dt As New DataTable()
Me.dataGridView1.DataSource = dt.DefaultView

Thanks LUC001
Your code works.


No problem glad to help, mark your thread as resolved.