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