关键是执行了多少次 sqlCompute 函数,每一次执行都是很耗时的。
或者试试改成下面这样,如果还是耗时,做具体实例发上来测试优化
systemready = false
Dim dt As Datatable = DataTables("半成品流水")
Dim dic As new Dictionary(of String, Double)
For Each dr As DataRow In dt.Select("")
Dim key = dr("半成品件号")
If dic.ContainsKey(key) = False Then
Dim dt1 As Integer = dt.sqlCompute("Sum(入库)","半成品件号 = '" & key & "'")
Dim dt2 As Integer = dt.sqlCompute("Sum(出库)","半成品件号 = '" & key & "'")
dr("库存") = dt1 - dt2
dic.Add(key, dt1 - dt2)
Else
dr("库存") = dic(key)
End If
Next
systemready = true