473,396 Members | 1,775 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,396 software developers and data experts.

Retrieve data from an Excel spreadsheet using ADO.NET connection objects

I want to retrieve data from an Excel file like how I would with a
database. I understand that I would have to use OLE DB. Somehow I
think I cannot get the connection string right, as the bit of code
fails at "objConn.Open()" with the error:
System.Data.OleDb.OleDbException: Could not find installable ISAM.

Can somebody please help me out? I'm still a learning programmer, so
if someone can point out my mistakes, it'll be great! Thanks!

Dim objConn As OleDbConnection
Dim objTrans As OleDbTransaction
Dim objCmd As OleDbCommand
Dim objRead As OleDbDataReader

Dim strSource As String = "C:\temp\data.xls"
Dim strConn As String = "Persist Security Info=False;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + strSource + ";" & _
"Extended Properties=Microsoft Excel 97-2000;"

objConn = New OleDb.OleDbConnection(strConn)
objConn.Open()

Dim strSQLQuery As String = "SELECT * FROM [Sheet1$]"

objCmd.CommandText = strSQLQuery
objRead = objCmd.ExecuteReader()

While objRead.Read()
' Manipulate data
End While

objTrans.Commit()
objConn.Close()
objConn = Nothing
Nov 21 '05 #1
1 3234
It might be the:
Extended Properties=Microsoft Excel 97-2000

You might want to try:
Extended Properties=Excel 8.0
The following topic may help:

Reading Excel Data into a Dataset (Visual Basic)
http://msdn.microsoft.com/library/en...deexamplereadi
ngexceldataintodataset.asp

hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

--------------------
| From: lu*******@gmail.com (funcSter)
| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Retrieve data from an Excel spreadsheet using ADO.NET connection
objects
| Date: 19 Jan 2005 10:54:45 -0800
| Organization: http://groups.google.com
| Lines: 35
| Message-ID: <9b**************************@posting.google.com >
| NNTP-Posting-Host: 202.91.205.118
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1106160886 9238 127.0.0.1 (19 Jan 2005
18:54:46 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Wed, 19 Jan 2005 18:54:46 +0000 (UTC)
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews.google.com!not-for-mail
| Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb:254806
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I want to retrieve data from an Excel file like how I would with a
| database. I understand that I would have to use OLE DB. Somehow I
| think I cannot get the connection string right, as the bit of code
| fails at "objConn.Open()" with the error:
| System.Data.OleDb.OleDbException: Could not find installable ISAM.
|
| Can somebody please help me out? I'm still a learning programmer, so
| if someone can point out my mistakes, it'll be great! Thanks!
|
| Dim objConn As OleDbConnection
| Dim objTrans As OleDbTransaction
| Dim objCmd As OleDbCommand
| Dim objRead As OleDbDataReader
|
| Dim strSource As String = "C:\temp\data.xls"
| Dim strConn As String = "Persist Security Info=False;" & _
| "Provider=Microsoft.Jet.OLEDB.4.0;" & _
| "Data Source=" + strSource + ";" & _
| "Extended Properties=Microsoft Excel 97-2000;"
|
| objConn = New OleDb.OleDbConnection(strConn)
| objConn.Open()
|
| Dim strSQLQuery As String = "SELECT * FROM [Sheet1$]"
|
| objCmd.CommandText = strSQLQuery
| objRead = objCmd.ExecuteReader()
|
| While objRead.Read()
| ' Manipulate data
| End While
|
| objTrans.Commit()
| objConn.Close()
| objConn = Nothing
|

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 ...
4
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
8
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept...
1
by: Mike P | last post by:
I'm trying to take some data from an Excel spreadsheet, put it into a dataset, and then update a SQL table with the data. I'm not 100% sure I'm doing this right, can somebody tell me what I'm...
4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
6
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be...
7
by: semijoyful | last post by:
OS: Win XP SP2 Access version: 2003 Excel version: 2003 I am new at this, as I am sure you have gathered from this post title:) I am working on a form where users can input data in Access and...
5
by: barbara_dave | last post by:
Hi All, I need to read data from a Excel spreadsheet, but I got the problem when I tried the code below: StringBuilder sbConn = new StringBuilder();...
7
Merlin1857
by: Merlin1857 | last post by:
Its great producing data for users to look at in your web pages and generally that is sufficient for their needs but sometimes you may want to supply your user with the data in a form they can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.