以文本方式查看主题

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

--  作者:sysckj
--  发布时间:2018/3/8 14:00:00
--  [原创]该代码增加条件
Dim dt1 As DataTable = DataTables("表B")
Dim dt2 As DataTable = DataTables("合并村")
\'dt1.StopRedraw
For Each dr As DataRow In dt1.Select("")
    Dim str As String = dr("家庭住址")
    str = str.Replace("1", "一").Replace("2", "二")
    
    For Each fdr As DataRow In dt2.Select("")
        Application.Doevents
        If fdr("合并前村") > "" AndAlso str.Contains(fdr("合并前村")) Then
            dr("合并前村") = fdr("合并前村")
            dr("合并后村") = fdr("合并后村")
        End If
    Next
    
Next
\'dt1.ResumeRedraw

增加一个条件表B更新数据前要求表B的乡镇字段合并村的乡镇字段一致才更新

--  作者:有点甜
--  发布时间:2018/3/8 14:31:00
--  
Dim dt1 As DataTable = DataTables("表B")
Dim dt2 As DataTable = DataTables("合并村")
\'dt1.StopRedraw
For Each dr As DataRow In dt1.Select("")
    Dim str As String = dr("家庭住址")
    str = str.Replace("1", "一").Replace("2", "二")
   
    For Each fdr As DataRow In dt2.Select("乡镇 = \'" & dr("乡镇") & "\'")
        Application.Doevents
        If fdr("合并前村") > "" AndAlso str.Contains(fdr("合并前村")) Then
            dr("合并前村") = fdr("合并前村")
            dr("合并后村") = fdr("合并后村")
        End If
    Next
   
Next
\'dt1.ResumeRedraw