以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请求指点,代码优化  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=15016)

--  作者:sunnykorla
--  发布时间:2011/12/9 18:08:00
--  请求指点,代码优化

原代码:

 

CurrentTable.DataTable.DataCols.Add("存在",Gettype(String),255)
For Each dr1 As DataRow In CurrentTable.DataTable.DataRows
    Dim dr2 As DataRow = DataTables("hushu").Find("NSRSBH =  \'" & dr1("NSRSBH") & "\'")
    If dr2 IsNot Nothing Then
        dr1("存在") = dr2("NSRMC")
    End If
Next

自己优化后代码:

CurrentTable.DataTable.DataCols.Add("存在",Gettype(String),255)
Dim lst1 As New List(of DataRow)
For Each dr1 As DataRow In CurrentTable.DataTable.DataRows
    Dim dr2 As DataRow = DataTables("hushu").Find("NSRSBH =  \'" & dr1("NSRSBH") & "\'")
    If dr2 IsNot Nothing Then
        \'dr1("存在") = dr2("NSRMC")
        lst1.Add(dr2)
    End If
Next
For Each dr1 As DataRow In CurrentTable.DataTable.DataRows
    For Each dr As DataRow In lst1
        dr1("存在") = dr("NSRMC")
    Next
Next

 

优化前17万行数据运行102秒,优化后基本无法运行。请求指点!


--  作者:狐狸爸爸
--  发布时间:2011/12/9 18:10:00
--  

CurrentTable.DataTable.DataCols.Add("存在",Gettype(String),255)
Dim lst1 As New List(of DataRow)
For Each dr1 As DataRow In CurrentTable.DataTable.DataRows
    Dim dr2 As DataRow = DataTables("hushu").Find("NSRSBH =  \'" & dr1("NSRSBH") & "\'")
    If dr2 IsNot Nothing Then
        \'dr1("存在") = dr2("NSRMC")
        lst1.Add(dr2)
    End If
Next
For Each dr As DataRow In lst1
    dr1("存在") = dr("NSRMC")
Next

 


--  作者:sunnykorla
--  发布时间:2011/12/12 15:37:00
--  

好像不行!

 


图片点击可在新窗口打开查看此主题相关图片如下:捕获.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2011-12-12 15:37:42编辑过]

--  作者:狐狸爸爸
--  发布时间:2011/12/12 15:53:00
--  
CurrentTable.DataTable.DataCols.Add("存在",Gettype(String),255)
Dim lst1 As New Dictionary(of DataRow,DataRow)
For Each dr1 As DataRow In CurrentTable.DataTable.DataRows
    Dim dr2 As DataRow = DataTables("hushu").Find("NSRSBH =  \'" & dr1("NSRSBH") & "\'")
    If dr2 IsNot Nothing Then
        lst1.Add(dr1,dr2)
    End If
Next
For Each dr1 As DataRow In lst1.Keys
    dr1("存在") = lst1(dr1)("NSRMC")
Next