Solved

ADODB Recordset is skipping the first line.

Posted on 2006-11-02
7
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:dacz
ID: 17859024
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
ID: 17859054
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
ID: 17859974
That did not resolve the issue.  Thanks though.  Any other takers?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:jmwheeler
ID: 17860094
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
ID: 17863823
>>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
ID: 17897959
Closed, 250 points refunded.
DarthMod
Community Support Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

738 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