以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 不重复加载 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=76681) |
-- 作者:sf020cf -- 发布时间:2015/11/3 13:58:00 -- 不重复加载 项目以后在不同电脑运作 用sql server 数据库 我在不同板块有一个按钮是把当前表数据加载到其他表的 为了避免数据重复 加了类似于以下代码的判断: If DataTables("员工").Find("身份证号码 = \'" & dr("身份证号码") & "\'") Is Nothing Then 但我表中并没有唯一性字段 所以只能这样吗 If DataTables("客服跟单").find("下单日期 = \'"& dr("下单日期") & "\' and MK号 = \'"& dr("MK号") & "\' and 城市 = \'"& dr("城市") & "\' and 客户 = \'"& dr("客户") & "\' and............ 下面还有这么多 送货地址/ 物料代码/ 数量/ 体积/ 重量 /收货时间 /是否采购订单) 有没有更简洁的代码 |
-- 作者:大红袍 -- 发布时间:2015/11/3 14:04:00 -- dim filter as string = "1=1" For Each dc As DataCol In DataTables("表A").datacols filter &= " And " & dc.name & " = \'" & dr(dc.name) & "\'" Next msgbox(filter) [此贴子已经被作者于2015/11/3 14:04:34编辑过]
|
-- 作者:大红袍 -- 发布时间:2015/11/3 14:06:00 -- dim filter as string = "1=1" For Each dc As DataCol In DataTables("表A").datacols filter &= " And convert(" & dc.name & ",\'System.String\') = \'" & dr(dc.name) & "\'" Next msgbox(filter) |
-- 作者:sf020cf -- 发布时间:2015/11/3 14:21:00 -- Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } For Each r As Row In Tables("配载订单").GetCheckedRows Next
就是这段代码 要在哪加判断 能否把数据加载完成后提示加载了多少条有效数据
|
-- 作者:大红袍 -- 发布时间:2015/11/3 14:27:00 -- Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim count As Integer = 0 For Each r As Row In Tables("配载订单").GetCheckedRows Dim filter As String = "1=1" For Each dc As String In Cols1 filter &= " And convert(" & dc & ",\'System.String\') = \'" & r(dc) & "\'" Next Dim dr As DataRow = DataTables("客服跟单").find(filter) If dr Is Nothing Then dr = DataTables("客服跟单").AddNew count += 1 End If For i As Integer = 0 To Cols1.Length -1 dr(Cols2(i)) = r(Cols1(i)) Next Next msgbox(count) |
-- 作者:sf020cf -- 发布时间:2015/11/3 14:34:00 -- 谢谢 版主 |
-- 作者:sf020cf -- 发布时间:2015/11/3 15:16:00 -- 以下是引用大红袍在2015/11/3 14:27:00的发言:
Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim count As Integer = 0 For Each r As Row In Tables("配载订单").GetCheckedRows Dim filter As String = "1=1" For Each dc As String In Cols1 filter &= " And convert(" & dc & ",\'System.String\') = \'" & r(dc) & "\'" Next Dim dr As DataRow = DataTables("客服跟单").find(filter) If dr Is Nothing Then dr = DataTables("客服跟单").AddNew count += 1 End If For i As Integer = 0 To Cols1.Length -1 dr(Cols2(i)) = r(Cols1(i)) Next Next msgbox(count) 版主 加载两次数据依然重复
|
-- 作者:大红袍 -- 发布时间:2015/11/3 15:28:00 -- 这样写
|
-- 作者:sf020cf -- 发布时间:2015/11/3 15:36:00 -- 依然是可以重复加载相同数据 |
-- 作者:大红袍 -- 发布时间:2015/11/3 15:37:00 -- 不会,我测试不会啊。
上传例子测试。 |