Foxtable(狐表)用户栏目专家坐堂 → [求助]关于Filler语句的排除重复问题


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

主题:[求助]关于Filler语句的排除重复问题

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


加好友 发短信
等级:婴狐 帖子:61 积分:480 威望:0 精华:0 注册:2016/7/20 8:54:00
[求助]关于Filler语句的排除重复问题  发帖心情 Post By:2016/8/1 11:16:00 [只看该作者]

我有A表和B表,每张表都有自己的设置的类似于主键列的ID列,想将A表中的数据用Filler语句搬到B表。

 

但在设置完排除重复值后,A表的所有数据都被搬了过去,因为ID列是没有重复的。

 

所以想问:在排除重复值的时候,如何将ID列不列入判断范围。


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


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

 要用这种方法

 

Dim Cols1() As String = {"来源列一","来源列二","来源列三"}
Dim Cols2() As String = {"接收列一","接收列二","接收列三"}
For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim dr2 As DataRow = DataTables("表B").find("第一列 = '" & dr1("第一列") & "' and 第二列 = '" & dr1("第二列") & "' and 第三列 = '" & dr1("第三列") & "'")
    If dr2 Is Nothing Then
        dr2 = DataTables("表B").AddNew()
    End If
    For i As Integer = 0 To Cols1.Length -1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
Next


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


加好友 发短信
等级:婴狐 帖子:61 积分:480 威望:0 精华:0 注册:2016/7/20 8:54:00
  发帖心情 Post By:2016/8/1 12:07:00 [只看该作者]

还是会全部复制过去。我的A表的数据是从外部数据源读下来的,读下来之后要把修改过的或新增的全部丢到B表去,而且不会替换掉B表原来的数据。

我换了您的代码,把ID列排除后,还是会把重复的搬过去。


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


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

 实例发上来。


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


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

Dim Cols1() As String = {"第一列","第二列","第三列"}
Dim Cols2() As String = {"第一列","第二列","第三列"}
For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim filter As String = "1=1"
    For i As Integer = 0 To cols1.length-1
        If dr1.IsNull(cols1(i)) Then
            filter &= " and " & cols2(i) & " is null"
        Else
            Dim dc As DataCol = DataTables("表B").datacols(cols2(i))
            If dc.IsString Then
                filter &= " and " & dc.name & " = '" & dr1(cols1(i)) & "'"
            ElseIf dc.IsBoolean Then
                filter &= " and " & dc.name & " = " & dr1(cols1(i))
            ElseIf dc.IsNumeric Then
                filter &= " and " & dc.name & " = " & dr1(cols1(i))
            ElseIf dc.IsDate Then
                filter &= " and " & dc.name & " = #" & dr1(cols1(i)) & "#"
            End If
        End If
    Next
    Dim dr2 As DataRow = DataTables("表B").find(filter)
    If dr2 Is Nothing Then
        dr2 = DataTables("表B").AddNew()
    End If
    For i As Integer = 0 To Cols1.Length -1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
Next

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


加好友 发短信
等级:婴狐 帖子:61 积分:480 威望:0 精华:0 注册:2016/7/20 8:54:00
  发帖心情 Post By:2016/8/1 18:00:00 [只看该作者]

 

[此贴子已经被作者于2016/8/1 21:19:15编辑过]

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


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

 参考5楼代码。

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


加好友 发短信
等级:婴狐 帖子:61 积分:480 威望:0 精华:0 注册:2016/7/20 8:54:00
  发帖心情 Post By:2016/8/3 9:58:00 [只看该作者]

还是会所有都复制过去。上面两行代码我没有添加ID列,但判断重复的时候好像都被列去判断范围了。


图片点击可在新窗口打开查看此主题相关图片如下:qq拼音截图未命名.jpg
图片点击可在新窗口打开查看


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


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

 上传实例,贴出代码。

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


加好友 发短信
等级:婴狐 帖子:61 积分:480 威望:0 精华:0 注册:2016/7/20 8:54:00
  发帖心情 Post By:2016/8/3 10:51:00 [只看该作者]

AfterOpenProject:

Dim Cols1() As String = {"T28CT","T28UT","T28DL","T28UserId","T28DeptId","T28PointId","F390","F391","F392","F394","F395","F396","F397","F398","F399","F400","F401","F402","F403","F404","F405","F406","F407","F408","F409","F410","F411","F412","F413","F414","F415","F416","F417","F418","F419","F420","F421","F422","F4367","F4368","F4370","F4371","F4372","F4373","F4374","F4375","F4376","F4377","F4378","F4379","F4380","F4381","F4382","F5140","F5221","F5222","F5223","F5224","F5225","F5226","F5299","F5308","F5310","F5311","F5312","F5313"}
Dim Cols2() As String = {"T246CT","T246UT","T246DL","T246UserId","T246DeptId","T246PointId","F4362","F4363","F4364","F4366","F4383","F4384","F4385","F4386","F4387","F4388","F4389","F4390","F4391","F4392","F4393","F4394","F4395","F4396","F4397","F4398","F4399","F4400","F4401","F4402","F4403","F4404","F4405","F4406","F4407","F4408","F4409","F4410","F4411","F4412","F4414","F4415","F4416","F4417","F4418","F4419","F4420","F4421","F4422","F4423","F4424","F4425","F4426","F5265","F5293","F5294","F5295","F5296","F5297","F5298","F5300","F5315","F5317","F5318","F5319","F5320"}
For Each dr1 As DataRow In DataTables("T28").Select("")
    Dim filter As String = "1=1"
    For i As Integer = 0 To cols1.length-1
        If dr1.IsNull(cols1(i)) Then
            filter &= " and " & cols2(i) & " is null"
        Else
            Dim dc As DataCol = DataTables("T246").datacols(cols2(i))
            If dc.IsString Then
                filter &= " and " & dc.name & " = '" & dr1(cols1(i)) & "'"
            ElseIf dc.IsBoolean Then
                filter &= " and " & dc.name & " = " & dr1(cols1(i))
            ElseIf dc.IsNumeric Then
                filter &= " and " & dc.name & " = " & dr1(cols1(i))
            ElseIf dc.IsDate Then
                filter &= " and " & dc.name & " = #" & dr1(cols1(i)) & "#"
            End If
        End If
    Next
    Dim dr2 As DataRow = DataTables("T246").find(filter)
    If dr2 Is Nothing Then
        dr2 = DataTables("T246").AddNew()
    End If
    For i As Integer = 0 To Cols1.Length -1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
Next
DataTables("T246").Save()

[此贴子已经被作者于2016/8/3 16:12:42编辑过]

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