473,473 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Importing excel data w/ oledb

I've been butting heads with this code, it always errors at
objAdapter1.Fill(objDataTable1)
Is oledb the best way to do this? How about ADO.NET?

Dim objDataTable1 As DataTable
Dim objConn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& strFilePath & ";Extended Properties=Excel 8.0")
objConn.Open()
Dim strCmd As String = String.Format("SELECT * FROM [Freeze
Data$]")
Dim objCmdSelect As OleDbCommand = New OleDbCommand(strCmd,
objConn)
Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect

objAdapter1.Fill(objDataTable1)

objAdapter1.Dispose()
objCmdSelect.Dispose()
objConn.Close()
objConn.Dispose()

Return objDataTable1

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
4 1883
Hi,

Couple of things.

1) connection string. Should have hdr = yes; Use 8.0 for excel 97, 9.0 for
2000, 10.0 for 2002 (xp), 11.0 for 2003

OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& strFilePath & ";Extended Properties=Excel 8.0; HDR = YES;")

2) make sure you have the worksheet name correct

Ken
-------------------
"Claud Balls" <Li**@trainer.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
I've been butting heads with this code, it always errors at
objAdapter1.Fill(objDataTable1)
Is oledb the best way to do this? How about ADO.NET?

Dim objDataTable1 As DataTable
Dim objConn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& strFilePath & ";Extended Properties=Excel 8.0")
objConn.Open()
Dim strCmd As String = String.Format("SELECT * FROM [Freeze
Data$]")
Dim objCmdSelect As OleDbCommand = New OleDbCommand(strCmd,
objConn)
Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect

objAdapter1.Fill(objDataTable1)

objAdapter1.Dispose()
objCmdSelect.Dispose()
objConn.Close()
objConn.Dispose()

Return objDataTable1

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #2
On Wed, 23 Mar 2005 16:57:04 -0800, Claud Balls <Li**@trainer.com> wrote:

¤ I've been butting heads with this code, it always errors at
¤ objAdapter1.Fill(objDataTable1)
¤ Is oledb the best way to do this? How about ADO.NET?
¤
¤ Dim objDataTable1 As DataTable
¤ Dim objConn As OleDbConnection = New
¤ OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
¤ & strFilePath & ";Extended Properties=Excel 8.0")
¤ objConn.Open()
¤ Dim strCmd As String = String.Format("SELECT * FROM [Freeze
¤ Data$]")
¤ Dim objCmdSelect As OleDbCommand = New OleDbCommand(strCmd,
¤ objConn)
¤ Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
¤ objAdapter1.SelectCommand = objCmdSelect
¤
¤ objAdapter1.Fill(objDataTable1)
¤
¤ objAdapter1.Dispose()
¤ objCmdSelect.Dispose()
¤ objConn.Close()
¤ objConn.Dispose()
¤
¤ Return objDataTable1
What error do you get when you butt heads?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #3
I've added HDR=YES, and I tried using Excel 9.0, since I have 2000, but
the open connection errors. The fill is still not working with a value
cannot be null message, which would lead me to believe my sql query
returned no results, which doesn't make sense, as it is pretty straight
forward:

Dim objCmdSelect As OleDbCommand = _
New OleDbCommand("SELECT * FROM [Freeze Data$]", objConn)

Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataTable1)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
On Thu, 24 Mar 2005 10:46:38 -0800, Claud Balls <Li**@trainer.com> wrote:

¤ I've added HDR=YES, and I tried using Excel 9.0, since I have 2000, but
¤ the open connection errors. The fill is still not working with a value
¤ cannot be null message, which would lead me to believe my sql query
¤ returned no results, which doesn't make sense, as it is pretty straight
¤ forward:
¤
¤ Dim objCmdSelect As OleDbCommand = _
¤ New OleDbCommand("SELECT * FROM [Freeze Data$]", objConn)
¤
¤ Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
¤ objAdapter1.SelectCommand = objCmdSelect
¤ objAdapter1.Fill(objDataTable1)

Actually HDR=Yes is not required unless the first row of the Worksheet contains column names.

I still don't have enough info with respect to your error message. Could you post the exact text?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #5

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

Similar topics

4
by: Little PussyCat | last post by:
Hello, I nee to write something that will transfer excel data into an SQL Server table. I have for another database application I wrote have it importing Excel spreadsheet data using cell by...
3
by: Geir Baardsen | last post by:
Hi! From one of my manufacturers I get new prices in an excel spreadsheet. Now I want to import this data to my access db. However, there is a difference: The items in MyAccess.db...
0
by: Syvman | last post by:
Is there a parameter to set to allow opening Excel file read only while it is already open by another user? I've tried the .mode setting in my connection string to adModeRead, but it still won't...
8
by: kinda | last post by:
Hi All, I have an Excel spreadsheet that I need to import to Access. I used the DoCmd.TransferSpreadSheet command but the problem I am facing is that all the field names are in Colums A1 to A15 and...
0
by: ramaraog80 | last post by:
Hi, Is it possible to import data from Excel Sheets to MySql. If possible please reply me with the detail Code ASAP.
2
by: WODJ | last post by:
Folks, I hope someone out there can please help me, not much hair left with this one. I'm importing excel data into a SQL server database using an Oledb connection in C#. The problemm is that...
1
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that...
4
by: greg | last post by:
Hi, I have a read only access file with a linked table that connects to a sybase database. So I can still add data to the table even though its read only since the table is really in sybase. ...
4
by: smugcool | last post by:
HI, I am trying to import an excel data. All the fields are geting imported properly. But i am geting error in the date field. I tried to keep the format both in excel and access very similar.But...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.