Link to home
Start Free TrialLog in
Avatar of jmwheeler
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.Connection")
set rs = CreateObject("ADODB.Recordset")

connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & s.GetEnvironmentString("Directory", 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.
Avatar of dacz
dacz

try to insert rs.MoveFirst in your Do-While Loop, for example:

Do While Not rs.eof

    rs.MoveFirst

    .....Code here
   
    rs.MoveNext

Loop
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
Avatar of jmwheeler

ASKER

That did not resolve the issue.  Thanks though.  Any other takers?
Nevermind, I found the answer myself. I needed to add ColNameHeader=False to my schema.ini file.  Please close this question.
Avatar of Anthony Perkins
>>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
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial