CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Posts
    145

    Using ADO to read a CSV file

    Anyone know how to use ADO to read a csv file?

    My requirements are:

    Must use ADO
    Must use a connection string (Cannot use a DSN)

    Thanks for the help


  2. #2
    Join Date
    Apr 2001
    Posts
    4

    Re: Using ADO to read a CSV file

    Hi,

    1.If you may use MS Access or MS Excel, you can store your CSV in them. It's easy to use ADO for MS Access or MS Excel Library for MS Exel.

    2.Without ADO: Just read the CSV like a normal text with:
    Open fullpath\xxx.csv For Input As #1
    Line Input #1, inputstring

    and search for each "," with:
    InStr(startInt, inputstring, ",", vbBinaryCompare)


    CU
    UU




  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Using ADO to read a CSV file

    This code will import csv file into an Access table

    Dim appAccess As New Access.Application
    '***********************************************************************
    '************* Open Access database and transfer file to DB ************
    'Must select Access 8 Object Library for Access 97 &
    'Access 9 Library for Access 2000 in Project|References
    'Open Database DB Path Exclusive
    appAccess.OpenCurrentDatabase "Path\Some..MDB", True

    ' Transfer text file to database
    appAccess.DoCmd.TransferText acImportDelim, , "Tablename", "Path\somefile.csv", 1

    ' Close
    appAccess.CloseCurrentDatabase

    ' Set object to Nothing
    Set appAccess = Nothing





    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jul 1999
    Posts
    145

    Re: Using ADO to read a CSV file

    Thank you for your suggestions!! but the code I will be using will be ASP-based on a web server without Access or Excel installed. I could use the FSO to open the file and parse it, but this could become complicated in situations where the seperator character is embedded in the data itself.

    I was hoping there would be a simpler way.



  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Using ADO to read a CSV file

    Nice solution.
    (still out of votes...)


    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured