以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]关于Filler语句的排除重复问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=88343) |
-- 作者:陌聲人 -- 发布时间:2016/8/1 11:16:00 -- [求助]关于Filler语句的排除重复问题 我有A表和B表,每张表都有自己的设置的类似于主键列的ID列,想将A表中的数据用Filler语句搬到B表。
但在设置完排除重复值后,A表的所有数据都被搬了过去,因为ID列是没有重复的。
所以想问:在排除重复值的时候,如何将ID列不列入判断范围。 |
-- 作者:大红袍 -- 发布时间:2016/8/1 11:19:00 -- 要用这种方法
Dim Cols1() As String = {"来源列一","来源列二","来源列三"} |
-- 作者:陌聲人 -- 发布时间:2016/8/1 12:07:00 -- 还是会全部复制过去。我的A表的数据是从外部数据源读下来的,读下来之后要把修改过的或新增的全部丢到B表去,而且不会替换掉B表原来的数据。 我换了您的代码,把ID列排除后,还是会把重复的搬过去。 |
-- 作者:大红袍 -- 发布时间:2016/8/1 12:08:00 -- 实例发上来。 |
-- 作者:大红袍 -- 发布时间: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 |
-- 作者:陌聲人 -- 发布时间:2016/8/1 18:00:00 --
[此贴子已经被作者于2016/8/1 21:19:15编辑过]
|
-- 作者:大红袍 -- 发布时间:2016/8/1 18:51:00 -- 参考5楼代码。 |
-- 作者:陌聲人 -- 发布时间:2016/8/3 9:58:00 -- 还是会所有都复制过去。上面两行代码我没有添加ID列,但判断重复的时候好像都被列去判断范围了。 |
-- 作者:大红袍 -- 发布时间:2016/8/3 10:26:00 -- 上传实例,贴出代码。 |
-- 作者:陌聲人 -- 发布时间: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"} [此贴子已经被作者于2016/8/3 16:12:42编辑过]
|