编码问题可以参考:
Using sr As IO.StreamReader = New IO.StreamReader(dlg.FileName,System.Text.Encoding.ASCII)
Encoding类型,可选的编码有:
Default
ASCII
BigEndianUnicode
Unicode
UTF32
UTF7
UTF8
具体是那种编码,自己尝试
------------------
Dim dlg As new OpenFileDialog
dlg.Filter = "文本文件|*.txt"
If dlg.ShowDialog = DialogResult.OK Then
Using sr As IO.StreamReader = New IO.StreamReader(dlg.FileName,System.Text.Encoding.UTF8) '直接从文件路径生成'
Dim line As String = sr.ReadLine() '读取一行
Do While line IsNot Nothing '如果不为空.为空说明读取完毕,结束循环
Dim cs() As String = line.trim().Replace(vbvr,"").Replace(vblf,"").Split(vbtab)
If cs.Length = 4 Then
Dim dr As DataRow = DataTables("表A").Addnew()
dr("第一列") = cs(0)
dr("第二列") = cs(1)
dr("第三列") = cs(2)
dr("第四列") = cs(3)
End If
line = sr.ReadLine() '读取下一行
Loop
End Using
End If