title: convert csv data to DataTable in VB.net, capturing column names from row 0
body: <p>I've adapted the code from the @tim-schmelter answer to question  <a href="https://stackoverflow.com/questions/11118678/convert-csv-data-to-datatable-in-vb-net">convert csv data to DataTable in VB.net</a>  (see below)</p>
  
  <p>I would like to parse in the column titles from row 0 of the csv file </p>
  
  <pre><code>DT|Meter Number|Customer Account Number|Serial Number|Port...
  </code></pre>
  
  <p>but I'm not having any luck trying to figure out how to do this.  any suggestions would be very appreciated.</p>
  
  <pre><code>Public Function csvToDatatable_2(ByVal filename As String, ByVal separator As String)
      '////////////////////////////////////////
      'Reads a selected txt or csv file into a datatable 
      'based on code from  http://stackoverflow.com/questions/11118678/convert-csv-data-to-datatable-in-vb-net
      '////////////////////////////////////////
      Dim dt As System.Data.DataTable
  
      Try
          dt = New System.Data.DataTable
          Dim lines = IO.File.ReadAllLines(filename)
          Dim colCount = lines.First.Split(separator).Length
  
          For i As Int32 = 1 To colCount
              dt.Columns.Add(New DataColumn("Column_" &amp; i, GetType(String)))
          Next
  
          For Each line In lines
              Dim objFields = From field In line.Split(separator)
              Dim newRow = dt.Rows.Add()
              newRow.ItemArray = objFields.ToArray()
          Next
  
      Catch ex As Exception
          Main.Msg2User(ex.Message.ToString)
          Return Nothing
  
      End Try
  
      Return dt
  
  End Function
  </code></pre>