-- 作者: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秒,优化后基本无法运行。请求指点!
|