jmwheeler
asked on
ADODB Recordset is skipping the first line.
I am using ADO to read a comma-delimited file. This is working fine except that it is skipping the first line in the file. I have already set the connection string to no header row. Sample code is below.
set conn = CreateObject("ADODB.Connec tion")
set rs = CreateObject("ADODB.Record set")
connString = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" & s.GetEnvironmentString("Di rectory", True) & _
"\;Extended Properties=" & Chr(34) & "text;HDR=NO;FMT=Delimited " & Chr(34)
conn.Open connString
rs.Open "SELECT * FROM " & fileDirectory & fileB, conn, adOpenStatic, adLockOptimistic, adCmdText
Do While Not rs.eof
.....Code here
rs.MoveNext
Loop
The RecordCount returned is actually correct for the file but it starts with the second line in the file and the last record is null filled. Any help with this is much appreciated.
set conn = CreateObject("ADODB.Connec
set rs = CreateObject("ADODB.Record
connString = "Provider=Microsoft.Jet.OL
"\;Extended Properties=" & Chr(34) & "text;HDR=NO;FMT=Delimited
conn.Open connString
rs.Open "SELECT * FROM " & fileDirectory & fileB, conn, adOpenStatic, adLockOptimistic, adCmdText
Do While Not rs.eof
.....Code here
rs.MoveNext
Loop
The RecordCount returned is actually correct for the file but it starts with the second line in the file and the last record is null filled. Any help with this is much appreciated.
i want to edit my post:
try to insert rs.MoveFirst after you get the recordsets, for example:
rs.Open "SELECT * FROM " & fileDirectory & fileB, conn, adOpenStatic, adLockOptimistic, adCmdText
If rs.RecordCount > 0 then
rs.MoveFirst
End if
Do While Not rs.eof
.....Code here
rs.MoveNext
Loop
try to insert rs.MoveFirst after you get the recordsets, for example:
rs.Open "SELECT * FROM " & fileDirectory & fileB, conn, adOpenStatic, adLockOptimistic, adCmdText
If rs.RecordCount > 0 then
rs.MoveFirst
End if
Do While Not rs.eof
.....Code here
rs.MoveNext
Loop
ASKER
That did not resolve the issue. Thanks though. Any other takers?
ASKER
Nevermind, I found the answer myself. I needed to add ColNameHeader=False to my schema.ini file. Please close this question.
>>Please close this question.<<
Please do it yourself. Here's how:
I answered my question myself. What do I do?
https://www.experts-exchange.com/help.jsp#hi70
Please do it yourself. Here's how:
I answered my question myself. What do I do?
https://www.experts-exchange.com/help.jsp#hi70
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do While Not rs.eof
rs.MoveFirst
.....Code here
rs.MoveNext
Loop