Foxtable(狐表)用户栏目专家坐堂 → 代码效率优化


  共有2786人关注过本帖树形打印复制链接

主题:代码效率优化

帅哥哟,离线,有人找我吗?
bobolan521
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:628 积分:7180 威望:0 精华:1 注册:2013/11/26 7:49:00
代码效率优化  发帖心情 Post By:2019/4/23 13:33:00 [只看该作者]

以下代码执行完毕,目前需要4分钟左右 请老师帮忙看一下,执行速度还可以再优化一下吗?


Dim gs As String ,dw As String , bb As String ,dfje As Decimal,je As Decimal,mxzje As Decimal

'''''''''查询需要计算请款总金额的清单
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELEC T 公司,单位,币别,sum(请款金额) as 请款总金额 from 请款单 group by 公司,单位,币别   order by 公司"
dt = cmd.ExecuteReader()
'''''''''查询需要计算请款总金额的清单

If dt.DataRows.Count > 0 Then
    For Each drb As DataRow In dt.DataRows
        bb = drb("币别")
        gs =  drb("公司")
        dw =  drb("单位")
        je =  drb("请款总金额")
        Dim cmd1 As New SQLCommand
        Dim dt1 As DataTable
        cmd1.C
        cmd1.CommandText = "Selec t _identify as 序号, 公司,单位,本期贷方发生额,发生期间 ,应支付期间,付款总金额,请款总金额,币别 FROM 科目余额表 where 公司 = '" & gs & "' " & _
        " And 单位 ='" & dw & "' and 币别='" & bb & "'order by 应支付期间 "
        dt1 = cmd1.ExecuteReader()
        If dt1.DataRows.Count > 0 Then
            mxzje = dt1.Compute("sum(本期贷方发生额)","")
            dfje=je - mxzje
            
            For Each dra As DataRow In  dt1.DataRows
                If dra("公司")=gs And dra("单位")=dw And dra("币别")=bb  Then
                    If je>= dra("本期贷方发生额") Then
                        dra("请款总金额") = dra("本期贷方发生额")
                        je = je - dra("本期贷方发生额")
                    Else
                        dra("请款总金额") = je
                        je = 0
                    End If
                End If
                ''''''''反写请款总金额
                
                Dim cmd2 As New SQLCommand
                Dim dt2 As DataTable
                cmd2.C
                cmd2.CommandText = "updat e 科目余额表 set 请款总金额 = '" & dra("请款总金额") & "' where _identify = '" & dra("序号") & "'"
                dt2 = cmd2.ExecuteReader()
                ''''''''反写请款总金额
            Next
        End If
    Next
End If




 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/23 15:22:00 [只看该作者]

 

每执行一次 ExecuteReader 耗时 0.5 秒。如果确实只能这样,加入事务

 

http://www.foxtable.com/webhelp/scr/2933.htm

 

 

 


 回到顶部