I wrote the following code to load a DataTable with a CSV file. My
problem is: If I include the line "MyTable.Clear()" before I start
loading the Table, I'm presented with the 2nd line of my CSV file
presented twice (rows 0 and 1 of the table) and the 1st line of the CSV
file is missing. If I remove the "Clear" statement, then all my data is
there, but there's a blank row at Row 0.
Help!?!?!?
Thanks!
--------- Begin Code -------------
Private Sub LoadFile2Grid(ByVal fileName As String)
Dim sr As StreamReader = New StreamReader(fileName) 'Opens the
file for reading
Dim strLine As String 'Holds each
line of the file as it reads
Dim MyArray() As String 'Holds each
delimited sub-string from the line
Dim i As Integer 'Counter for
loops
Dim myRow As DataRow
myTable.Clear() 'Empty out
the table before loading the file
strLine = sr.ReadLine 'Reads in
the first line of the file
While Not strLine Is Nothing
MyArray = Split(strLine, ",") 'Splits line
up into an array of fields
'If not enough columns for the next line, add as many as we
need
If myTable.Columns.Count < MyArray.GetUpperBound(0) + 1 Then
For i = myTable.Columns.Count To
MyArray.GetUpperBound(0)
GridAddColumn("F" & i.ToString)
Next
End If
myRow = myTable.NewRow()
For i = MyArray.GetLowerBound(0) To MyArray.GetUpperBound(0)
myRow(i) = MyArray(i)
Next
myTable.Rows.Add(myRow)
strLine = sr.ReadLine
End While
sr.Close()
End Sub
------------ End Code ----------------
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!