472,986 Members | 2,906 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 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 3208
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.