[英]How to use Group by from a Dataview values in vb.net
是否有任何方法可以在datatview values上使用group by。我可以对dataview中的值进行排序,但如何在数据视图中对数据进行分组(在vb.net中)我想在数据视图上应用聚合函数如何使其成为可能?
You can group objects from a DataView
or any other data collection using the GroupBy method extension. 您可以使用GroupBy方法扩展从
DataView
或任何其他数据集合对对象进行分组。
For a DataView you'd first have to cast it as IEnumerable(Of DataRowView)
. 对于DataView,您首先必须将其
IEnumerable(Of DataRowView)
为IEnumerable(Of DataRowView)
。 Here's a very simplistic example: 这是一个非常简单的例子:
Dim groupedRows =
myDataView.Cast(Of DataRowView).GroupBy(Function(r) r("MyField"))
If you're using a typed DataSet
you might find it much easier to group on typed DataRow
instead as you'll be able to use hard properties for grouping rather than Object
values obtained with string references: 如果您使用的是类型化
DataSet
您可能会发现在类型化DataRow
上分组更容易,因为您将能够使用硬属性进行分组而不是使用字符串引用获取的Object
值:
Dim groupedRows =
myDataTable.GroupBy(function(r) r.MyField)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.