Data table sorting in VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 277
The following will sort the records in the datatable based on the data column age.

Dim dt As New DataTable()
Dim dr As DataRow
dr = dt.NewRow()
dr(0) = 21
dr(1) = "AAA"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 20
dr(1) = "AAA"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 22
dr(1) = "AAA"
dt.Rows.Add(dr)

'sorting
dt.AsEnumerable().[Select](Function(dr) dr("age")).OrderbyDesc(Function(o) o).ToList()

Comments or Responses

Login to post response