以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]同步两个表的数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92346) |
-- 作者:fuucc -- 发布时间:2016/11/1 15:07:00 -- [求助]同步两个表的数据 A表是基本表,没有重复数据,B表是基于A表所有字段后加了几个字段构成的表,A表的内容改动后,如何同步到B表。 在B表的窗体加同步按钮代码如下:
Dim cmd As New SQLCommand Dim dt As DataTable Dim sCols() As String = {"xingming","xingbie","sfzhm","minzu","year","beizhu"} Dim dCols() As String = {"xingming","xingbie","sfzhm","minzu","year","beizhu"} dt = DataTables("A表") For Each dr As DataRow In dt.DataRows If DataTables("B表").Find("sfzhm= \'" & dr("sfzhm") & "\'") Is Nothing Then Dim nr As DataRow = DataTables("xszzbb").AddNew() For i As Integer =0 To sCols.Length -1 nr(dCols(i)) = dr(sCols(i)) Next Else Dim nr As DataRow = DataTables("B表").Find("sfzhm= \'" & dr("sfzhm") & "\'") For i As Integer =0 To sCols.Length -1 nr(dCols(i)) = dr(sCols(i)) Next End If Next 这个对于B表没有重复数据是有效的,有重复数据就没有用了,请问下改如何写同步代码。 |
-- 作者:有点蓝 -- 发布时间:2016/11/1 16:28:00 -- 有重复数据应该如何处理呢 |
-- 作者:有点色 -- 发布时间:2016/11/1 18:57:00 -- Dim sCols() As String = {"xingming","xingbie","sfzhm","minzu","year","beizhu"}
|
-- 作者:fuucc -- 发布时间:2016/11/5 0:27:00 -- 谢谢二楼解答,高手啊 |