vb.net - Linq: How do I add an Order By clause to this statement -


i have linq statement takes existing datatable , gets list of distinct years using groupby , gets count of items have year , places result in datatable.

dim yearquery = existingdt.asenumerable().groupby(function(yi) yi.field(of string)(existingdt.columns("year")))  dim yearresults new datatable()  yearresults.columns.add("year") yearresults.columns.add("quantity")  each yi in yearquery      yearresults.rows.add( yi.key, yi.count) next 

this works great try might have not been able figure out how produce results yearresults datatable has data in descending year order.

why year string , not integer? if can't change have parse value:

dim orderedyearquery = existingdt.asenumerable().     groupby(function(row) int32.parse(row.field(of string)("year"))).     orderbydescending(function(grp) grp.key) 

Comments