Results 1 to 4 of 4

Thread: How to convert CSV file to datareader?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    478

    How to convert CSV file to datareader?

    How to convert CSV file to datareader?

    I google it but only find out how to convert datareader to CSV file.

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: How to convert CSV file to datareader?

    You mean use a datareader to read from a CSV file?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: How to convert CSV file to datareader?

    Yeah, because that would put a CSV into a datareader.
    My usual boring signature: Nothing

  4. #4
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: How to convert CSV file to datareader?

    If you want to read the contents of a CSV file into a DataTable, you can use something like this (assuming that the first line of the file is the Column Names):
    Code:
          
    connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & NameOfFolder
          conn = New OdbcConnection(connectionString)
          'we only pass it the folder.  The csv file import is in the query which follows
    
          da = New OdbcDataAdapter("SELECT * FROM " & sFilename, conn)
          da.AcceptChangesDuringFill = False
          iFileRecords = da.Fill(dt)
    NameOfFolder: the folder where your CSV file lives.
    sFileName: the Filename of the CSV file.
    This will get all of your CSV records into a DataTable (dt) that you can use.
    Or you can use an ODBC DataReader if you want...

    Code:
          Dim ODBC_Command As New OdbcCommand("SELECT * FROM " & sFilename, conn)
          ODBC_Command.CommandType = CommandType.Text
          Dim ODBC_Reader As OdbcDataReader
    
          ODBC_Reader = ODBC_Command.ExecuteReader
          While ODBC_Reader.Read
            'Do something
          End While

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