Foxtable(狐表)用户栏目专家坐堂 → 请求指点,代码优化


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

主题:请求指点,代码优化

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


加好友 发短信
等级:婴狐 帖子:71 积分:702 威望:0 精华:0 注册:2010/8/29 20:29:00
请求指点,代码优化  发帖心情 Post By: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秒,优化后基本无法运行。请求指点!


 回到顶部