Dim lj As String = Args(0)
Dim bh As String = Args(1)
Dim jc As String = Args(2)
Dim sl As Integer = Args(3)
Dim i As Long = 0
Dim line As String
If Forms("AC200").Opened Then
Dim constring As String = "Server=192.168.1.254;Database=AC200;User Id=AC200;Password=r6XcbWt7NWn7;"
Using conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(constring)
conn.Open() '打开链接
Using copy = New System.Data.SqlClient.SqlBulkCopy(conn)
copy.Destinati '指定服务器上目标表的名称
Dim cls() As String = {"编号", "架次", "时标", "目标转速", "实际转速", "控制器状态", "电压", "电流"}
Dim clss() As String = {"时标", "目标转速", "实际转速", "控制器状态", "电压", "电流"}
For Each cl As String In cls
copy.ColumnMappings.Add(cl, cl)
Next
copy.BatchSize = 1000
copy.BulkCopyTimeout = 3600
Dim drs As New List(Of System.Data.DataRow)(sl)
Using sr As IO.StreamReader = New IO.StreamReader(lj) '直接从文件路径生成'
line = sr.ReadLine() '读取一行
i = 1
Forms("AC200").Controls("js").Text = i
Dim idx As Integer = 1
Dim dr As System.Data.DataRow
Dim dt As System.Data.DataTable = DataTables("AC200").basetable.clone
Do While line IsNot Nothing '如果不为空继续执行.为空说明读取完毕,结束循环
'数据处理
dr = dt.NewRow()
dr("编号") = bh
dr("架次") = jc
Dim ls() As String = line.Split(",")
For ii As Integer = 0 To ls.Length - 1
dr(clss(ii)) = ls(ii)
Next
drs.Add(dr)
If idx = sl Then
copy.WriteToServer(drs.ToArray)
idx = 1
drs.Clear
dt.Clear
Else
idx += 1
End If
i = i + 1
Forms("AC200").Controls("js").Text = i
line = sr.ReadLine() '读取下一行
Loop
End Using
If drs.Count > 0 Then
copy.WriteToServer(drs.ToArray)
drs.Clear
End If
Forms("AC200").Controls("js").Text = "OK"
End Using
End Using
End If
GC.Collect()
此主题相关图片如下:qq截图20240913182144.jpg
使用以上代码导入大概200w行以后就会报错,有没有什么解决方法?
‘导入按钮的代码
SystemReady = False
Functions.AsyncExecute("TXTR", e.Form.Controls("lj").Value, e.Form.Controls("bh").Value, e.Form.Controls("jc").Value)
SystemReady = True
文件太大,发不过来,是不是datatable也有行数限制?
代码有每10000行就清空的代码,不是datatable的问题。
文件大发给QQ客服测试