Parsing *.csv with ADO?

J

Joe Duchtel

Hello -

I need to parse a *.csv file without much effort so I wanted to use an
ADO. I have done that successfully to read from an Excel file
(Extended Properties="Excel 8.0;HDR=NO") but somehow I cannot figure
out *.csv files.

Here is what I have ...

Dim lFileName As String = "C:\"

Dim lConnection As New ADODB.Connection

lConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=" & lFileName & ";" & "Extended Properties=Text;"

lExcelConnection.Open()

The problem is that I cannot specify a file name ABC.csv without
getting an exception of 'C:\ABC.csv is not a valid path.'.

How do I access the data in the *.csv file?

I used the following for Excel but since I use Extended
Properties=Text, I assume I need to do something differently?

Dim lRBTQuery As String = "SELECT * FROM [Sheet1$A1:C1]"
Dim lADORecordSet As New ADODB.Recordset
lADORecordSet.Open(Source:=lRBTQuery, ActiveConnection:=lConnection)

How can I read all lines of the *.csv file?

Any suggestions?

Thanks,
Joe
 
J

Joe Duchtel

Joe,

I am not sure if this is what you mean, however this is a quiet standard
method to use a csv file as a table in Net.

http://www.vb-tips.com/CSVDataSet.aspx

Your equivalent of the recordset is in this case ds.Tables(0)

I hope this is what you need

Cor




I need to parse a *.csv file without much effort so I wanted to use an
ADO.  I have done that successfully to read from an Excel file
(Extended Properties="Excel 8.0;HDR=NO") but somehow I cannot figure
out *.csv files.
Here is what I have ...
Dim lFileName As String = "C:\"
Dim lConnection As New ADODB.Connection
lConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=" & lFileName & ";" & "Extended Properties=Text;"

The problem is that I cannot specify a file name ABC.csv without
getting an exception of 'C:\ABC.csv is not a valid path.'.
How do I access the data in the *.csv file?
I used the following for Excel but since I use Extended
Properties=Text, I assume I need to do something differently?
Dim lRBTQuery As String = "SELECT * FROM [Sheet1$A1:C1]"
Dim lADORecordSet As New ADODB.Recordset
lADORecordSet.Open(Source:=lRBTQuery, ActiveConnection:=lConnection)
How can I read all lines of the *.csv file?
Any suggestions?
Thanks,
Joe- Hide quoted text -

- Show quoted text -

Hello -

This is great ... works beautifully!

Thanks a lot,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top