回楼上的:
Dim intColCount As Integer = 0
Dim blnFlag As Boolean = True
Dim mydt As DataTable = New DataTable
Dim mydc As DataColumn
Dim mydr As DataRow
Dim FilePath As String
If OpenFile_dg.ShowDialog = DialogResult.OK Then '打开一个文件选择框
FilePath = Me.OpenFile_dg.FileName
End If
Dim strline As String
Dim aryline As String()
Dim i As Integer
If FilePath <> Nothing Then '当文件名不为空
Dim mysr As System.IO.StreamReader = New System.IO.StreamReader(FilePath, System.Text.Encoding.Default)
strline = mysr.ReadLine()
While strline <> Nothing
aryline = strline.Split(vbTab) '以TAB键为分隔符
'aryline = strline.Split("|".ToCharArray())
If blnFlag Then
blnFlag = False
intColCount = aryline.Length
For i = 0 To aryline.Length - 1
mydc = New DataColumn(aryline(i))
mydt.Columns.Add(mydc)
'mydt.Rows.Add(New Object() {"员工号", "日期", "时间"})
Next
Else
mydr = mydt.NewRow()
For i = 0 To intColCount - 1
mydr(i) = aryline(i)
Next
mydt.Rows.Add(mydr)
End If
strline = mysr.ReadLine()
End While
End If