Foxtable(狐表)用户栏目专家坐堂 → 不重复加载


  共有2875人关注过本帖树形打印复制链接

主题:不重复加载

帅哥哟,离线,有人找我吗?
sf020cf
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
不重复加载  发帖心情 Post By: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............   下面还有这么多   

送货地址/ 物料代码/ 数量/ 体积/ 重量 /收货时间 /是否采购订单)

有没有更简洁的代码


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 14:21:00 [只看该作者]

Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" }
Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" }

For Each r As Row In Tables("配载订单").GetCheckedRows
    Dim dr As DataRow = DataTables("客服跟单").AddNew()
    For i As Integer = 0 To Cols1.Length -1
        dr(Cols2(i)) = r(Cols1(i))
            Next

Next

 

就是这段代码 要在哪加判断 能否把数据加载完成后提示加载了多少条有效数据

 


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 14:34:00 [只看该作者]

谢谢 版主

 回到顶部
帅哥哟,离线,有人找我吗?
sf020cf
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By: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)

版主 加载两次数据依然重复

 


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/11/3 15:28:00 [只看该作者]

这样写


Dim Cols1() As String = {"第一列", "第二列"}
Dim Cols2() As String = {"第一列","第二列"}
Dim count As Integer = 0
For Each r As Row In Tables("表A").GetCheckedRows
    Dim filter As String = ""
    Dim str As String = ""
    For Each dc As String In Cols1
        filter &= "isnull(convert(" & dc & ",'System.String'),'')+'|'+"
        str &= r(dc) & "|"
    Next
    filter = "(" & filter.trim("+") & ") = '" & str & "'"
    Dim dr As DataRow = DataTables("表B").find(filter)
    If dr Is Nothing Then
        dr = DataTables("表B").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
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 15:36:00 [只看该作者]

依然是可以重复加载相同数据

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/11/3 15:37:00 [只看该作者]

不会,我测试不会啊。

 

上传例子测试。


 回到顶部
总数 18 1 2 下一页