422,363 Members | 2,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,363 IT Pros & Developers. It's quick & easy.

Excel connection strings

100+
P: 101
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;")
  5.  
  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()
  11.  
  12.         DataGridView1.DataSource = dt
  13.         DataGridView1.Refresh()
  14.  
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


100+
P: 101
I found my answer. The file name was misspelled.
2 Weeks Ago #2

Post your reply

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