以文本方式查看主题

-  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=51278)

--  作者:sh16
--  发布时间:2014/5/23 10:26:00
--  求教 代码执行效率问题

For Each dr1 As DataRow In DataTables("结果").DataRows
    Dim dr As DataRow
    dr = DataTables("配置").Find("[内容] like \'*" & dr1("PON口") & " ont " & dr1("ONUID") & " gemport 1*\'")
    If dr IsNot Nothing Then
        Dim nr() As String
        nr = dr("内容").split(" ")
        dr1("PVLAN") = nr(4)
        dr1("CVLAN") = nr(13)
    Else
        dr1("PVLAN") = Nothing
        dr1("CVLAN") = Nothing
    End If
Next

 

这段代码有问题吗?执行了5分钟。。。。。"结果"表格有5000行,"配置"表有4万行。


--  作者:有点甜
--  发布时间:2014/5/23 10:33:00
--  

应该是触发了Datacolchanged里面的代码,试试这样

 

SystemReady = False

For Each dr1 As DataRow In DataTables("结果").DataRows
    Dim dr As DataRow
    dr = DataTables("配置").Find("[内容] like \'*" & dr1("PON口") & " ont " & dr1("ONUID") & " gemport 1*\'")
    If dr IsNot Nothing Then
        Dim nr() As String
        nr = dr("内容").split(" ")
        dr1("PVLAN") = nr(4)
        dr1("CVLAN") = nr(13)
    Else
        dr1("PVLAN") = Nothing
        dr1("CVLAN") = Nothing
    End If
Next

SystemReady = True


--  作者:sh16
--  发布时间:2014/5/23 10:36:00
--  
可是我没有设置Datacolchanged事件啊,我是在命令窗口输入的,用了你的代码一样非常慢。
[此贴子已经被作者于2014-5-23 10:37:35编辑过]

--  作者:有点甜
--  发布时间:2014/5/23 10:38:00
--  
以下是引用sh16在2014-5-23 10:36:00的发言:
可是我没有设置Datacolchanged事件啊

 

先用2楼代码,如果测试成功,你绝对是在结果表的datacolchanged里面写了代码。

 

如果测试不成功,请上传例子测试


--  作者:有点甜
--  发布时间:2014/5/23 10:40:00
--  

 上传项目。


--  作者:sh16
--  发布时间:2014/5/23 10:42:00
--  

Datacolchanged肯定没设置,用了你的代码一样的情况。只是简单的查找,查找条件包含几段。仅此而已。卡了至少5分钟。


--  作者:Bin
--  发布时间:2014/5/23 10:43:00
--  
这样也许能再快点

Dim Dic As new Dictionary(of DataRowDataRow)
dim drr as datarow

SystemReady = False

For Each dr1 As DataRow In DataTables("结果").DataRows
    Dim dr As DataRow
    dr = DataTables("配置").Find("[内容] like \'*" & dr1("PON口") & " ont " & dr1("ONUID") & " gemport 1*\'")
    If dr IsNot Nothing Then
        dic.add(dr1,dr)

    Else
        dic.add(dr1,drr)
    End If
Next

For Each dr As DataRow In dic.Keys
    if dic(dr) isnot nothing then

        Dim nr() As String

        nr = dic(dr)("内容").split(" ")
        dr("PVLAN") = nr(4)
        dr("CVLAN") = nr(13)

    else

         dr("PVLAN") = Nothing

        dr("CVLAN") = Nothing

    end if
Next

SystemReady = True


--  作者:sh16
--  发布时间:2014/5/23 10:43:00
--  
等下再传,卡着动不了
--  作者:有点甜
--  发布时间:2014/5/23 10:44:00
--  

 1、数据量的问题问题。

 

 2、like查询本来就很慢的,得看比较的内容的多少。

 

 3、需要优化代码。


--  作者:Bin
--  发布时间:2014/5/23 10:45:00
--  
试试7楼代码