Click to See Complete Forum and Search --> : Using ADO to read a CSV file


Mikesc
April 13th, 2001, 08:47 AM
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

UU4U
April 13th, 2001, 09:35 AM
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

Iouri
April 13th, 2001, 10:09 AM
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
iouri@hotsheet.com

Mikesc
April 13th, 2001, 10:20 AM
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.

Cimperiali
April 13th, 2001, 10:26 AM
Nice solution.
(still out of votes...)


Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.