'目的:判断tb中是否包含tbltaizhang的记录且tb中字段【春检年度】=cmb年度.Text,关键字段是【台账号】
'若包含,则用tbltaizhang中的字段值去修改tb中的相同字段值,若不包含,则在tb中增加相应记并赋值。
'tbltaizhang中有5000条记录,下面代码执行需要耗时500秒左右,请老师们看看该如何优化
Dim time1 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "正在增加行,请稍后..."
Application.DoEvents()
Dim tb As Table = e.Form.Controls("Table1").Table
Dim tbltaizhang As Table = e.Form.Controls("Table2").Table
tb.StopRedraw
Dim cmb年度 As WinForm.ComboBox = e.Form.Controls("cmb年度")
Dim mydate As Date = Functions.Execute("SQLTIME")
For Each ydr As Row In tbltaizhang.Rows
Dim wz As Integer = tb.FindRow("[台账号] = '" & ydr("台账号") & "' And [春检年度] = '" & cmb年度.Text & "'")
If wz >= 0 Then
tb.Position = wz
Else
Dim dr As Row = tb.AddNew()
End If
tb.Current("部门编号")= ydr("部门编号")
tb.Current("部门")= ydr("部门")
tb.Current("春检年度")= e.Form.Controls("cmb年度").text
tb.Current("台账号")= ydr("台账号")
tb.Current("台账号old")= ydr("台账号old")
tb.Current("地点")= ydr("地点")
tb.Current("台账名称")= ydr("台账名称")
tb.Current("录入人")= _UserTag
tb.Current("录入终端")= _UserPCip
tb.Current("录入日期")= mydate
Next
tb.ResumeRedraw
Dim time2 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "耗时:" & Format((time2-time1).TotalSeconds,"0.0000") & "秒"