需要从一份130M的文本中读取数据(有1780000行),并写入数据表中,执行以下代码变得时间好长好长,最后死机了,
请前辈帮忙修改一下代码,
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.Default) |
Dim line As String = sr.ReadLine() '读取一行
Dim rs1() As String = line.Split(vbcr)
For i As Integer = 0 To rs1.Length - 1
Dim cs() As String = rs1(i).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
Next
Do While line IsNot Nothing '如果不为空.为空说明读取完毕,结束循环
line = sr.ReadLine() '读取下一行
Dim rs() As String = line.Split(vbcr)
For i As Integer = 0 To rs.Length - 1
Dim cs() As String = rs(i).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
Next
Loop
End Using
End If