473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Excel connection strings

102 64KB
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.  
Apr 5 '18 #1
1 2066
sc5502
102 64KB
I found my answer. The file name was misspelled.
Apr 5 '18 #2

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

Similar topics

4
by: Minh Tran | last post by:
In order to minimize the number of connection strings I have to use to access different databases on the same Sql Server, I was considering storing all stored procedures in just one database. I...
7
by: aacool | last post by:
Hi, I've been trying to open an Excel connection through OLEDB with the code below: string ConnectString =@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fileName.Text +...
1
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
3
by: Bob | last post by:
Over the life of a distributed app, it is possible for the connection string that it was configured with initailly needs to change. You can't scope a connection string setting to user so that it...
2
by: Mike P | last post by:
I've always put my connection strings in the web.config, but I've just recently seen an example of a connection string in a resource file. What are the advantages of doing this, and could you do it...
3
by: Harry Strybos | last post by:
Hi All I have a really strange problem occurring in my application. When I read in the application settings for connection strings the following happens: Here are my connection string settings...
11
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Is there a way in ASP.NET 2.0 to have different connection strings settings in a web.config files that are dynamically used based upon the server that the web application is running on? For...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.