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


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

主题:不重复加载

帅哥哟,离线,有人找我吗?
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............   下面还有这么多   

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

有没有更简洁的代码


 回到顶部
帅哥哟,离线,有人找我吗?
sf020cf
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | 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

 

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

 


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


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

谢谢 版主

 回到顶部
帅哥哟,离线,有人找我吗?
sf020cf
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | 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)

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

 


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


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

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

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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 15:55:00 [显示全部帖子]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目2_201511031553.zip

在回单异常窗口中 全选行 提交 (多次)
应付款项中提交多少次就加载多少次数据

 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 16:18:00 [显示全部帖子]

以下是引用大红袍在2015/11/3 15:49: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 = "1=1"
    For Each dc As String In Cols1
        If r.IsNull(dc) Then
            filter &= " and " & dc & " is null"
        Else
            Dim c As Col = Tables("表B").Cols(dc)
            If c.IsNumeric Then
                filter &= " and " & dc & " = " & r(dc)
            ElseIf c.IsBoolean Then
                If r(dc) = True Then
                    filter &= " and " & dc & " = true"
                Else
                    filter &= " and " & dc & " = false"
                End If
            ElseIf c.IsDate Then
                filter &= " and " & dc & " = #" & r(dc) & "#"
            Else
                filter &= " and " & dc & " = '" & r(dc) & "'"
            End If
        End If
    Next

    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
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 16:59:00 [显示全部帖子]

会不会是空值引起的 我在项目中用这代码一直都可以加载重复数据

 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/11/3 17:24:00 [显示全部帖子]

Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","司机","车牌","车型","车数","出车日期" ,"异常描述","处理结果","责任方","回单异常原因","责任单位","解决措施","补单司机","罚款金额"}
Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","司机","车牌","车型","车数","出车日期","异常描述","处理结果","责任方","回单异常原因","责任单位","解决措施","补单司机","罚款金额" }


 换上这个就不行

 

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

 

这个就可以

 


 回到顶部