Foxtable(狐表)用户栏目专家坐堂 → [求助]代码优化的问题


  共有1988人关注过本帖平板打印复制链接

主题:[求助]代码优化的问题

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


加好友 发短信
等级:六尾狐 帖子:1287 积分:10368 威望:0 精华:1 注册:2018/1/20 12:40:00
[求助]代码优化的问题  发帖心情 Post By:2021/1/28 13:25:00 [只看该作者]

目前有段代码是为了把“内网数据源”的数据读取出来的功能,但是目前由于里面的 遍历行的代码,所以导致运行很慢,想问下这种有没有可能用 SQLReplaceFor 或者其他什么方式简化呢。

Dim ps As String = args(0)  '-----部门

Dim ncb1 As WinForm.NumericComboBox = Forms("任务插入").Controls("NumericComboBox1")

If Connections.Contains("内网数据源") =True Then
    'Dim st2 As Date = Date.Now
    
    Dim d As Date= Date.Today.AddMonths(0 - ncb1.Value)
    Dim d1 As Date = New Date(d.Year,d.Month,1) '最近两个月的进度记录
  
    Dim rwjl As New SQLCommand
    rwjl.C
    rwjl.CommandText = "SE/ECT _identify,日期,编号,任务状态,当前进度,预期进度,提审内容,通过截图 From {任务进度记录} where 日期>= '" & d1 &"' And 部门 In (" & ps & ")"
    dtrw= rwjl.ExecuteReader(True)
    
    '=-------确认办公地点属于哪个分部
    Dim gs As String
    Dim cmd As New SQLCommand
    CMD.C
    cmd.CommandText = "Se/ect 归属地 From {服务器连接列表} Where 办公地点 = '"& SQLselect &"'"
    gs = cmd.ExecuteScalar()
    systemready =False
    For Each r1 As DataRow In DataTables("XMFP").DataRows
        Dim rdd As DataRow = dtry.Find("姓名 = '" & r1("成员") &"'")
        If rdd IsNot Nothing Then
            '---------------
            'test += r1("成员")
            If rdd("人员归属")= gs Then
                If r1("任务状态")<> "通过"  Then
                    
                    Dim max As Date
                    max= dtrw.Compute("max(日期)","编号 = '"& r1("_identify") &"'")
                    Dim fdr1 As DataRow = dtrw.Find("编号= '"& r1("_identify") & "'and 日期 = '"& max &"' ")
                    Dim fdr2 As DataRow = dtrw.Find("编号= '"& r1("_identify") & "'and 日期 = '"& date.Today &"' ")
                    Dim fdr3 As DataRow = dtrw.Find("编号= '"& r1("_identify") & "'and (通过截图 is not null or 通过截图 <>'')")  '----------------找通过截图行
                    
                    'Dim fdrxx As DataRow = dtrw.Find("编号= '23240'and 日期 = '"& max &"' ")
                    If fdr1 IsNot Nothing AndAlso (r1("任务状态")<> "待截图" AndAlso r1("任务状态")<> "关闭")  Then
                        r1("任务状态") = fdr1("任务状态")
                    End If
                    If fdr2 IsNot Nothing Then
                        
                        r1("当前进度") = fdr2("当前进度")
                    End If
                    If fdr3 IsNot Nothing Then
                        
                       
                        
                        r1("通过截图")=fdr3("通过截图")
                      
                        r1.Save
                    End If
                End If
                
                
                
                
            End If
        End If
        '
    Next
    systemready =True
  
End If

 回到顶部