By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Excel connection strings

P: 102
I want to populate a data grid view from an Excel spreadsheet. Here is my code. I get an error

System.Data.OleDb.OleDbException: '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?

Expand|Select|Wrap|Line Numbers
  1.   Dim dt As New DataTable
  2.         Dim cn As System.Data.OleDb.OleDbConnection
  3.         Dim cmd As System.Data.OleDb.OleDbDataAdapter
  4.         cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ace.OLEDB.12.0;" & "data source=H:\Documents\Desktop\TESTexcel.xlsx;Extended Properties=Excel 12.0;")
  6.         ' Select the data from Sheet1 of the workbook.
  7.         cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn)
  8.         cn.Open()
  9.         cmd.Fill(dt)
  10.         cn.Close()
  12.         DataGridView1.DataSource = dt
  13.         DataGridView1.Refresh()
Apr 5 '18 #1
Share this Question
Share on Google+
1 Reply

P: 102
I found my answer. The file name was misspelled.
Apr 5 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.