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


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

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

帅哥哟,离线,有人找我吗?
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秒,优化后基本无法运行。请求指点!


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


加好友 发短信
等级:管理员 帖子:47449 积分:251065 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:71 积分:702 威望:0 精华:0 注册:2010/8/29 20:29:00
  发帖心情 Post By:2011/12/12 15:37:00 [只看该作者]

好像不行!

 


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

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47449 积分:251065 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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

 回到顶部