以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]保存时有点慢,求助优化  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=69278)

--  作者:aduydgd
--  发布时间:2015/6/2 15:28:00
--  [求助]保存时有点慢,求助优化
我有个订单表和订单明细表,在录入完数据后,我首先要判断订单明细表的编码和金额列是空的,先删除数据,然后在把订单表的当前数据ID写入到订单明细表的当前所有增加的行的ID列,下面的代码感觉很慢还会闪,求高手优化一下,谢谢!

For Each dD As DataRow In DataTables("DINGDAN").DataRows
    If dD.IsNull("JIGOU") Or dD.IsNull("CANGKU") Or dD.IsNull("GONGYS")
        MessageBox.Show("【机构】【仓库】【供应商】不能为空!","提示" )
    End If
Next
For Each dr As DataRow In DataTables("RUKU_TABLE1").DataRows
    If dr("编码") = ""  Or dr.IsNull("金额") Then
        dr.Delete()
        DataTables("dingdan").Save
        For Each dr1 As DataRow In DataTables("RUKU_TABLE1").DataRows
            If dr1.IsNull("id") Then
                dr1("id") = Tables("DINGDAN").Current("id")
            End If
        Next
        DataTables("RUKU_TABLE1").Save
    End If
Next

--  作者:Bin
--  发布时间:2015/6/2 15:41:00
--  
闪可以在代码最前面加入

talbes("表名").StopRedraw

最后加入   talbes("表名").ResumeRedraw

Save放到循环外

talbes("表名").StopRedraw
For Each dr As DataRow In DataTables("RUKU_TABLE1").DataRows
    If dr("编码") = ""  Or dr.IsNull("金额") Then
        dr.Delete()
        DataTables("dingdan").Save
        For Each dr1 As DataRow In DataTables("RUKU_TABLE1").DataRows
            If dr1.IsNull("id") Then
                dr1("id") = Tables("DINGDAN").Current("id")
            End If
        Next
        
    End If
Next

DataTables("RUKU_TABLE1").Save
talbes("表名").ResumeRedraw



--  作者:狐狸爸爸
--  发布时间:2015/6/2 16:35:00
--  

循环语句中出现:

DataTables("dingdan").Save

 

等于每次循环,都要保存一下,不可以在循环结束后再保存吗?