以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何实现B表如何从A表获取到B表不存在的记录  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=109611)

--  作者:whtb999
--  发布时间:2017/11/15 17:05:00
--  如何实现B表如何从A表获取到B表不存在的记录
我想把A表中的数据插入到B表,但是条件是,A表.第一列 在 B表中的第一列中不存在的数据,请问各位专家指导一下。(B表中的列和A表中数据类型相同)
--  作者:有点甜
--  发布时间:2017/11/15 17:11:00
--  
Dim dt As DataTable = DataTables("表A")
For Each dr As DataRow In dt.DataRows
    If DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'") Is Nothing Then
        Dim nr As DataRow = DataTables("表B").AddNew()
        For Each dc As DataCol In dt.DataCols
            nr(dc.name) = dr(dc.name)
        Next
    End If
Next

--  作者:whtb999
--  发布时间:2017/11/15 17:35:00
--  
谢谢版主,如果我的B表中的列比A表中的少,或是名字不完全一样怎么处理呢? 这样写对吗
Dim dt As DataTable = DataTables("表A")
For Each dr As DataRow In dt.DataRows
    If DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'") Is Nothing Then
        Dim nr As DataRow = DataTables("表B").AddNew()
          nr("a")=dr("d")
nr("b")=dr("c")
nr("c")=dr("f")
nr("f")=dr("q")
    End If
Next
[此贴子已经被作者于2017/11/15 17:41:58编辑过]

--  作者:有点甜
--  发布时间:2017/11/15 17:39:00
--  
Dim dt As DataTable = DataTables("表A")
Dim dt2 As DataTable = DataTables("表B")
For Each dr As DataRow In dt.DataRows
    If dt2.Find("第一列 = \'" & dr("第一列") & "\'") Is Nothing Then
        Dim nr As DataRow = dt2.AddNew()
        For Each dc As DataCol In dt.DataCols
            If dt2.datacols.contains(dc.name) Then
                nr(dc.name) = dr(dc.name)
            End If
        Next
    End If
Next

--  作者:whtb999
--  发布时间:2017/11/15 17:44:00
--  
谢谢版主,写的真的太好了!