我有一个这样的数据表
invoice_number invoice_date customer_name item_name
1 14/01/2019 Mr.A Item1
2 15/01/2019 Mr.B Item1
3 15/01/2019 Mr.C Item2
1 15/01/2019 Mr.A Item2
2 20/01/2019 Mr.B Item5
我想要的
我想将除
invoice_number invoice_date customer_name
1 14/01/2019 Mr.A
2 15/01/2019 Mr.B
3 15/01/2019 Mr.C
到目前为止我尝试过的事情
Dim temp = (From p In Invoice_printing.Tables("inv_for_print").AsEnumerable()
Select New With {.inv_number = p.Field(Of String)("invoice_number"),
.inv_date = p.Field(Of Date)("invoice_date"),
.ol_name = p.Field(Of String)("ol_name")}).ToList()
Dim inv_selected_date = temp.GroupBy(Function(x) New With {Key x.inv_number, Key x.inv_date, Key x.ol_name}).ToList()
For Each inv In inv_selected_date
Dim newItem As New ListViewItem(inv.Key.inv_number)
newItem.SubItems.Add(inv.Key.ol_name)
newItem.SubItems.Add(CType(inv.Key.inv_date, String))
lv_inv_list.Items.Add(newItem)
Next
它有效,但是由于日期重复,发票编号1和2在ListView中出现两次。我该怎么办?我的Linq知识非常有限。除了将数据放入多维数组,运行嵌套循环并删除重复的条目外,我别无选择。
答案 0 :(得分:1)
在您的问题下查看我的评论。如果我对您的理解正确,那么我认为这就是你想要的:
var inv_selected_date = temp.GroupBy(i => i.invoice_number).Select(iv => iv.First()).ToList();