analyzing a csv using sql commands


B

bj daniels

From a Microsoft article, I got some basic information on using sql
techniques to read a csv file - I am using the code below, which does work.

Unfortuneately, when I try to make the sql statement fancier (select * from
webdata.csv where Name='bj') I get an error. similiar errors occur if I try
to reference the column by name with the datareader (dr.item("Name") as
opposed to dr.item(0)).

Though I am experimenting on some small csv files, my eventual goal is to
use something like this to analyze large (400MB) log files.

Any thoughts or additional articles would be a great help.

thanks


-------------------------------------
Public Sub ReadCSVnet()
Dim Conn As OleDbConnection
Dim dr As OleDbDataReader
Dim da As OleDbDataAdapter
Dim myCommand As OleDbCommand

Dim strPathtoTextFile As String
Dim sql As String


strPathtoTextFile = "C:\Data\"
sql = "Select * from webdata.csv"

Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=" & strPathtoTextFile & ";" & "Extended
Properties=""text;HDR=YES;FMT=Delimited""")

myCommand = New OleDbCommand(sql, Conn)
Conn.Open()
dr = myCommand.ExecuteReader()


While dr.Read
msg.Text += "Name: " & dr.Item(0) & " - "
msg.Text += "occupation: " & dr.Item(1) & "<br>"
End While
dr.Close()
Conn.Close()

End Sub
-------------------------------------
csv file looks like
"name", "occupation"
"bj", "director"
"neil", "web"


bj daniels
(e-mail address removed)
 
Ad

Advertisements


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