analyzing a csv using sql commands

Discussion in 'ASP .Net' started by bj daniels, May 12, 2004.

  1. bj daniels

    bj daniels Guest

    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
     
    bj daniels, May 12, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Ross
    Replies:
    0
    Views:
    595
    Joe Ross
    Aug 30, 2005
  2. Mike Landis

    Analyzing and tyding Java code

    Mike Landis, Oct 21, 2003, in forum: Java
    Replies:
    5
    Views:
    500
    Christopher Dean
    Oct 23, 2003
  3. Cross Eyed Admin
    Replies:
    3
    Views:
    815
    Cross Eyed Admin
    Jan 16, 2004
  4. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,977
    Thomas Stegen
    Jun 28, 2003
  5. Tim Stanka
    Replies:
    1
    Views:
    807
    Jeff Epler
    Aug 2, 2004
Loading...

Share This Page