Solved

ADODB Recordset is skipping the first line.

Posted on 2006-11-02
7
305 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:jmwheeler
7 Comments
 
LVL 1

Expert Comment

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

Do While Not rs.eof

    rs.MoveFirst

    .....Code here
   
    rs.MoveNext

Loop
0
 
LVL 1

Expert Comment

by:dacz
Comment Utility
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
0
 
LVL 11

Author Comment

by:jmwheeler
Comment Utility
That did not resolve the issue.  Thanks though.  Any other takers?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 11

Author Comment

by:jmwheeler
Comment Utility
Nevermind, I found the answer myself. I needed to add ColNameHeader=False to my schema.ini file.  Please close this question.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
>>Please close this question.<<
Please do it yourself.  Here's how:

I answered my question myself. What do I do?
http://www.experts-exchange.com/help.jsp#hi70
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
Comment Utility
Closed, 250 points refunded.
DarthMod
Community Support Moderator
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now