Dim Tj,T As String Dim dr As DataRow Dim n1,n2,n As Integer Dim dt1,dt2 As DataTable dt1 = DataTables("表A") dt2 = DataTables("表B") Dim tb As Table = Tables("表B") for each dr in dt1.select("路名 is not null") Tj = "路名 ='" & dr("路名") & "' and 状态 = '在用'" n1 = val(dt2.Compute("min(房)",Tj)) n2 = val(dt2.Compute("max(房)",Tj)) if n2 > n1 AndAlso n1 > 0 then tb.Redraw = False For n = n1+1 to n1+3 T = Tj.Replace("在用","虚拟") & " and 房 = '" & n & "'" if dt2.Find(T) is not Nothing then Dim r As Row = tb.addnew r("路名") = dr("路名") r("街名") = dr("街名") r("号") = dr("号") r("栋") = dr("栋") r("房") = n r("状态") ="虚拟" end if Next For n = n2-3 to n2-1 T = Tj.Replace("在用","虚拟") & " and 房 = '" & n & "'" if dt2.Find(T) is not Nothing then Dim r As Row = tb.addnew r("路名") = dr("路名") r("街名") = dr("街名") r("号") = dr("号") r("栋") = dr("栋") r("房") = n r("状态") ="虚拟" end if Next tb.Redraw = true end if Next