以文本方式查看主题

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

--  作者:wangnovel
--  发布时间:2017/1/21 0:07:00
--  数据比对问题

表A

  ID  X1   X2    X3 
  11   a  f g  
  12   r   t   y 
  13   u  i    o


表B

 ID    Y1 Y2   
  11   v   n 
  12  m  k  
  14   l  p 

 

两表(均为内部表)各有记录若干,并按ID值进行排序。现在需要对两张表进行操作,操作之前要进行检测,检测两表的ID值是否一一对应相等,如果不对应,应进行提示。提示以表A为准,如上图,系统应提示ID为13的记录与表B不匹配

请问,检测代码如何写比较好?

[此贴子已经被作者于2017/1/21 1:04:09编辑过]

--  作者:有点蓝
--  发布时间:2017/1/21 9:16:00
--  
Dim ids As List(Of String) = DataTables("表B").GetValues("ID")
For Each dr As DataRow In DataTables("表A").DataRows
    If ids.Contains(dr("ID")) = False Then
        msgbox(dr("ID") & "不在表B")
    End If
Next

--  作者:有点蓝
--  发布时间:2017/1/21 9:17:00
--  
或试试

Dim drs As List(of DataRow)  = DataTables("表A").SQLSelect("ID not in (select distinct ID from 表B)")
For Each dr As DataRow In drs
    msgbox(dr("ID") & "不在表B")
Next

--  作者:wangnovel
--  发布时间:2017/1/22 19:59:00
--  
非常感谢!