DataSet Group Implementing in VB.NET
We know a DataSet does not support GROUP BY and recently I needed GROUP BY in one of my applications. This attached class shows how to implement GROUP BY in a DataSet.
Recently I needed GROUP BY feature applied to a DataSet in VB.NET. I found the following article Implement a DataSet GROUP BY Helper Class in Visual C# .NET on MSDN, which was very useful.
Nipun Tomar helped me converting C# code to VB.NET, which is attached in this article. This is what CreateGroupByTable method looks like. See the attached source code for more details.
Public Function CreateGroupByTable(ByVal TableName As String, ByVal SourceTable As DataTable, ByVal FieldList As String) As DataTable
If FieldList Is Nothing Then
Throw New ArgumentException("You must specify at least one field in the field list.")
Dim dt As DataTable = New DataTable(TableName)
For Each Field As FieldInfo In GroupByFieldInfo
Dim dc As DataColumn = SourceTable.Columns(Field.FieldName)
If Field.Aggregate Is Nothing Then
dt.Columns.Add(Field.FieldAlias, dc.DataType, dc.Expression)
If Not (ds Is Nothing) Then