:?: 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
Thanks

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"
        Try

            ' 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;")
            MyConnection.Open()
            ' Select the data from Sheet of the workbook.
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [test$]", MyConnection)
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            exellgrid.DataSource = DtSet
            MyConnection.Close()
        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?

Hi,

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;""")
theConnection.Open()
Dim theDataAdapter As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", theConnection)
Dim theDS As New DataSet()
Dim dt As New DataTable()
theDataAdapter.Fill(dt)
Me.dataGridView1.DataSource = dt.DefaultView

Thanks LUC001
Your code works.

Hi,

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

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.