Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 44,026 times

Related Categories

Read text files into ADO recordsets

Often, you may have cause to read a comma-delimited, or some other
form of delimitation, into an ADO recordset. However, if your text
file doesn't contain header information, you may encounter odd
behavior in which ADO uses data in the first record as the recordset's
field names.

This glitch results because, by default, ADO assumes that each text
file will contain headers on the first row. So how do you indicate
otherwise? One hint can be found in the connection string generated by
Visual Basic when it connects to a text file, as seen here:

connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & App.Path & ";" _
        & "Extended Properties='text;FMT=Delimited'"

As you can see, the connection string contains a section called
Extended Properties, which indicates a delimited text file. By adding
a third argument to this section, we can tell ADO that the file doesn't
contain headers. The argument named HDR takes YES or NO as its sole
value. With this extra argument in place, the completed connection
string looks like this:

connCSV.Open "Provider=Microsoft.Jet" _
        & ".OLEDB.4.0;Data Source=" & App.Path _
        & ";Extended Properties='text;HDR=NO;" _
        & "FMT=Delimited'"

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Creating recordsets from text files

    Posted by UNNIMENON on 04 Jul 2005

    04th July, 2005

    Dear Mr.Steve,

    Trust the below basic idea of mine will help you in exploring the subject
    matter.
    Basic :
    1. The Text File CAN contain some data that are repeating in nature
    ...

  • Creating recordsets from text files

    Posted by Steve Moore on 04 Oct 2002

    Hello to everybody out there. a request from a programmer beginner.
    This is probably a very basic request but can any one help with telling me how to set up/define a record set
    from an existing text...

  • Please, help

    Posted by hristo_serafimov on 12 Mar 2002

    Hello,

    Can somebody tell me where to find a full description of the "Extended Properties"?

    I have made tests with text files and ADO connections and I found that ADO connections works with text ...