Hey!
I want to get count of repeating values in my datatable, preferably using linq query because there are a lot of rows.
I think I can get it using the group by function for linq query? so far here’s mine:
(From d In inDT.AsEnumerable
Group d By k=d("ID").toString.trim Into grp=Group
Let A = New Object(){k, <count here?>}
Select outDT.Rows.Add(A)).CopyToDataTable
So far, I have successfully grouped all ID’s only, but not sure how to get the count or the syntax. I’m really new to linq query so any help would be greatly appreciated, thanks!
intDT.AsEnumerable.
GroupBy(Function(r) r("ID")).
Select(Function(g)
Dim row As DataRow = outDT.NewRow
row.ItemArray = {g.Key, g.Count}
Return row
End Function
).CopyToDataTable
give a try on:
ensure that the outDT Datatable is created (2 Cols: 1 for the key, 2 for the count)
(From d In inDT.AsEnumerable
Group d By k=d(“ID”).toString.trim Into grp=Group
Let A = New Object(){k, grp.Count}
Select outDT.Rows.Add(A)).CopyToDataTable