谢谢狐爸老师的指教!通过后台汇总,前台遍历填充,运行时间从原来的近5秒缩短到0.25秒(代码如下),速度提升近20倍。再次衷心感谢狐爸老师!!
Dim cmd1 As New SQLCommand
Dim dt1 As DataTable
cmd1.Connection Name = "MES"
cmd1.CommandText = "S elect 批次编号,Max(拔卡时间) As 结束时间,Max(结束标记) As 结束标记 F ROM {扎包记录} Group By 批次编号"
dt1 = cmd1.ExecuteReader()
Dim cmd2 As New SQLCommand
Dim dt2 As DataTable
cmd2.Connection Name = "MES"
cmd2.CommandText = "S elect 批次编号 F ROM {工位数据} Group By 批次编号"
dt2 = cmd2.ExecuteReader()
For Each dr As DataRow In DataTables("采集批次").DataRows
If dr.IsNull("日期") = False Then
dr("结束时间") = dt1.Compute("Max(结束时间)", "批次编号 = '" & dr("批次编号") & "'")
Dim pr1 As DataRow = dt1.Find("批次编号 = '" & dr("批次编号") & "'and 结束标记 = 2")
Dim pr2 As DataRow = dt2.Find("批次编号 = '" & dr("批次编号") & "'")
If pr1 IsNot Nothing Then
dr("结束标记") = True
Else
dr("结束标记") = False
End If
If pr2 IsNot Nothing Then
dr("工位数据") = True
Else
dr("工位数据") = False
End If
End If
Next
DataTables("采集批次").Save()
Tables("采集批次").AutoSizeCols()
[此贴子已经被作者于2016/6/18 11:18:34编辑过]