Connect to XLS through ADO - Field names not coming through
- From: Beowulf <beowulf_is_not_here@xxxxxxxxxxx>
- Date: Thu, 07 Dec 2006 15:25:02 -0500
I didn't have any luck getting responses microsoft.public.data.ado. I thought I might have some success reposting here. Any help will be appreciated.
---
I have an Excel worbook with 1 *** in it that looks like this:
A B C D
1 Westat Tech Screen Export
2
3 CandidateId 6343 6344 6345
4 279864 <empty> <empty> <empty>
5 280325 Yes Weekend evenings Yes
I want to connect to it through ADO so I can just use a recordset to
read some data out of it in a structured manner. I am getting a recordset connected to the workbook in this manner:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
With cnn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Temp\report.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"""
.Open
End With
' Open recordset
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cnn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "SELECT * FROM [Sheet1$A3:D100]"
End With
After .Open, .Field(0).Name is "Candidate ID" field, but the remaining fields are named F2 to Fxx instead of using the number that is in the header row.
It seems that Jet is treating the numbers as data even though HDR=YES. Is there some way to force Jet to stop trying to be smart and just read the data in the manner specified? Thanks.
.
- Prev by Date: Re: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- Next by Date: C++ connection to OleDbConnection
- Previous by thread: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- Next by thread: C++ connection to OleDbConnection
- Index(es):