VB .NET Linq过滤器表行 [英] VB .NET Linq filter table rows
问题描述
我需要在vb.net中使用linq(不必在乎它的圆点表示法样式还是其他样式)
I need to use linq in vb.net (don't really care if its dot notation style or the other one)
我需要过滤一个看起来像这样的数据表
I need to filter a DataTable that looks like this
legacyparent1,name1,id1
legacyparent1, name1, id1
legacyparent1,name2,id2
legacyparent1, name2, id2
legacyparent1,name1,id1
legacyparent1, name1, id1
legacyparent1,name2,id2
legacyparent1, name2, id2
legacyparent1,name1,id1
legacyparent1, name1, id1
legacyparent1,name2,id2
legacyparent1, name2, id2
我只需要两行具有不同的名称和ID.
I need just two rows with distinct name and id.
它是由遗留连接引起的,我现在没有时间尝试重写.
Its caused by a legacy join that I don't have time to try to rewrite right now.
推荐答案
不是最有效的方法,但这是最简单的方法:
Not the most efficient, but here is the short way:
Dim dataTable2 = dataTable1.DefaultView.ToTable(true)
或使用散列集的效率更高:
or a bit more efficient with hashed set:
Dim dt2 = dataTable1.Rows.Cast(Of DataRow).Distinct(DataRowComparer.Default).CopyToDataTable
这篇关于VB .NET Linq过滤器表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!