VB.Net Program to read TAB Seperated CSV File Header and Data Rows

Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 1070
Public Function GetDataTable(strFileName As String) As System.Data.DataTable

Dim dt = New DataTable()
Dim lineFields = File.ReadAllLines(strFileName).[Select](Function(line) line.Split("|"C))
dt.Columns.AddRange(lineFields.First().[Select](Function(i) New DataColumn(i)).ToArray())
'add header
lineFields.Skip(1).ToList().ForEach(Function(i) dt.Rows.Add(i))
'add data rows
Return dt
End Function

Comments or Responses

Login to post response