以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助 表B接收表A的数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=145407)

--  作者:jackyfashion
--  发布时间:2020/1/18 18:53:00
--  求助 表B接收表A的数据
老师:
您好!
d im dt as date = Da te.Today.Ad dDays(-7)
If Try ConnectHost(lt61) Then
    D im cmd As Ne w S QLC ommand
    cm d.Conne cti
    cmd.Com man dText = "UPD ATE {表 B} SET ym yfjjad = \'" & dt & "\'"
    cm d.Exe cute NonQuery()
    Dat aT ables ("表B").Load()
    For Each dr1 As Data Row In DataT ables("表A").Select("[日期] >= #" & dt & "#")
        Dim dr2 As DataRow = DataT ables("表B").Ad dNew()
        For Ea ch dc As Da taCol In Da taTables("表A").Da taCols
            dr2(dc.Name) = dr1(dc.name)
        Next
    Next
Else
请老老师! 
如果  "表A"  跟接  "表B"  有相同的编号, "表B"  就复盖原来的数据,
如果不存在相同的编号 "表B" 就增加新行,插入数据.
请老师指教!!!
谢谢!!!

--  作者:jackyfashion
--  发布时间:2020/1/18 21:40:00
--  
老师:
您好!
找到如下代码:
dim dt as table = tables("表A")
For Each dr As DataRow In dt.DataRows
    For i As Integer = 0 To DataTables("表B").DataRows.Count -1
        If DataTables("表B").Find("编号 = \'" & dr("编号") & "\'") Is Nothing Then
            Dim nr As DataRow = DataTables("mxqrymyf").AddNew()
            For Each dc As DataCol In dt.DataCols
                nr(dc.name) = dr(dc.name)
            Next
        End If
    Next
Next
如果编号相同就复盖表B的数据.
请老师指点,怎么加代码!
谢谢!!!

--  作者:sloyy
--  发布时间:2020/1/19 0:52:00
--  
如果  "表A"  跟接  "表B"  有相同的编号, "表B"  就复盖原来的数据,
如果不存在相同的编号 "表B" 就增加新行,插入数据.

按照这个逻辑 ,可以先清空表B

--  作者:有点蓝
--  发布时间:2020/1/19 10:25:00
--  
    For Each dr1 As Data Row In DataTables("表A").Select("[日期] >= #" & dt & "#")
        Dim dr2 As DataRow = DataTables("表B").find("编号=\'" & dr1("编号") & "\'")
if dr2 is nothing then
dr2 = DataTables("表B").AddNew()
end if
        For Each dc As DataCol In DataTables("表A").DataCols
            dr2(dc.Name) = dr1(dc.name)
        Next
    Next

--  作者:jackyfashion
--  发布时间:2020/1/19 14:24:00
--  
谢谢两位老师!!!
谢谢!!!