I want to populate a data grid view from an Excel spreadsheet. Here is my code. I get an error
System.Data.Ole Db.OleDbExcepti on: 'The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.'
on the cmd.Fill(DT). What is wrong?
System.Data.Ole Db.OleDbExcepti on: 'The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.'
on the cmd.Fill(DT). What is wrong?
Code:
Dim dt As New DataTable
Dim cn As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbDataAdapter
cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ace.OLEDB.12.0;" & "data source=H:\Documents\Desktop\TESTexcel.xlsx;Extended Properties=Excel 12.0;")
' Select the data from Sheet1 of the workbook.
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn)
cn.Open()
cmd.Fill(dt)
cn.Close()
DataGridView1.DataSource = dt
DataGridView1.Refresh()
Comment