以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]集合  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=26755)

--  作者:nblwar
--  发布时间:2012/12/13 10:31:00
--  [求助]集合

如何将两个集合合并成一个不重复的集合

Dim Arys As List(Of String())  = DataTables("冷轧物流").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")
Dim Ary1s As List(Of String())  = DataTables("冷轧盘点表").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")

[此贴子已经被作者于2012-12-13 10:31:46编辑过]

--  作者:lin_hailun
--  发布时间:2012/12/13 10:46:00
--  
 简单的做法是,使用查询表联合两个表,然后获取。

Dim cmd As New SQLCommand
cmd.CommandText = "select a.第一列, a.第二列, a.第三列 from {表A}, {表B}"
Dim dt As DataTable = cmd.ExecuteReader
Dim ary As List(Of String()) = dt.GetUniqueValues("", "第一列", "第二列", "第三列")
msgbox(ary.count)
[此贴子已经被作者于2012-12-13 10:53:23编辑过]

--  作者:nblwar
--  发布时间:2012/12/13 11:00:00
--  

Dim Arys As List(Of String())  = DataTables("冷轧物流").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")
Dim Ary1s As List(Of String())  = DataTables("冷轧盘点表").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")
For Each Ary1 As String() In Ary1s
    If Arys.Contains(Ary1) = False Then
        Arys.Add(Ary1)
    End If
Next

 

为什么提取的会有重复的?? 其中品种跟保税两列有空值

[此贴子已经被作者于2012-12-13 11:02:59编辑过]

--  作者:lin_hailun
--  发布时间:2012/12/13 11:30:00
--  
Dim Ary1s As List(Of String())  = DataTables("冷轧物流").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")
Dim Ary2s As List(Of String())  = DataTables("冷轧盘点表").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")

Dim Ary3s As List(Of String())  = DataTables("冷轧物流").GetUniqueValues("[熔铸编号] IS NOT NULL", "品种","合金","保税")

For Each Ary2 As String() In Ary2s
    For Each Ary1 As String() In Ary1s
        For i As Integer = 0 To Ary1.Length
            If Ary1(i) <> Ary2(i) Then
                Ary3s.Add(Ary2)
                Exit For
            End If
        Next
    Next
Next