Hi there,
When parsing csv file into a datatable, it doesn't show the first line in a datagridview. What am I missing here?
thanks!
When parsing csv file into a datatable, it doesn't show the first line in a datagridview. What am I missing here?
thanks!
VB.NET:
Dim dt As New DataTable
Dim i As Integer
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser _
("c:\employee.txt")
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.Delimiters = New String() {","}
Dim f As Integer = MyReader.ReadFields.Length
For i = 1 To f
dt.Columns.Add()
Next
Do While Not MyReader.EndOfData
Try
dt.Rows.Add(MyReader.ReadFields())
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
Loop
End Using
Me.DataGridView1.DataSource = dt
Last edited by a moderator: