Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't use a <code>.Split()</code> function to read your csv data. Not only does it cause the kind of error you just ran into but it's slower as well. You need a <em>state machine</em> -based parser. That will be faster and make it easier to correctly handle quote-enclosed text.</p> <p>I have an example here:<br> <a href="https://stackoverflow.com/questions/1544721/reading-csv-files-in-c/1544743#1544743">Reading CSV files in C#</a></p> <p>and there's also a highly-respected CSV reader on codeplex you can use:<br> <a href="http://www.codeproject.com/KB/database/CsvReader.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/database/CsvReader.aspx</a></p> <hr> <p>You'd use my code like this:</p> <pre><code>Function DataTableFromCSV(ByVal filename As String) As DataTable Dim table As New DataTable Dim colAdded As Boolean = False For Each record As IList(Of String) In CSV.FromFile(filename) ''# Add column headers on first iteration If Not colAdded Then For Each token As String In record table.Columns.Add(token) Next token colAdded = True Else ''# add the row to the table Dim row As DataRow = table.NewRow() For i As Integer = 0 To table.Columns.Count - 1 row(i) = record(i) Next table.Rows.Add(row) End If Next record Return table End Function </code></pre> <p>If you're using .net 3.5 or later, I'd write it a little differently to pull the column creation out of the for each loop (using type inference and <code>.Take(1)</code> ), but I wanted to be sure this would work with .Net 2.0 as well. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload