I'm using VS2010 with VB.Net.
I have a function that reads in a csv file to a datatable. My problem is that the last couple rows in the datatable are blank. I need to ignore these rows. I've tried checking if the Line Legnth is > 0, but it still brings in. I'm assuming the Legnth check doesn't work b/c there are commas in the line. I've tried checking the value of the first column in the datatable after each line writes to it and then deleting it if it is empty or null but this didn't work either. I would prefer to not write it to the datatable if I can catch it before. Here's what I'm working with...
Dim sr As New StreamReader(path)
sr.ReadLine() 'skip the header line
Dim sFileData As String = sr.ReadToEnd()
Dim sLines As String() = sFileData.Split(ControlChars.Lf)
Dim dtRecs As New DataTable()
Dim sArray As String() = sLines(0).Split(","c)
For Each s As String In sArray
Dim row As DataRow
Dim sLastLine As String = ""
For Each ss As String In sLines
If ss.Length > 0 Then
row = dtRecs.NewRow()
sLastLine = ss.Replace(Convert.ToString(ControlChars.Cr), "")
row.ItemArray = sLastLine.Split(","c)