Sorting a Data Table


I tried to sort a data table with following two ways

table.DefaultView.Sort = "Town ASC, Cutomer ASC"

table.Select("", "Town ASC, Cutomer ASC")

But none of them wasn't worked. It always displays data in original order. Do you have any idea to solve the problem.

This question is tagged with .net

~ Asked on 2012-09-18 08:14:49

The Best Answer is


This was the shortest way I could find to sort a DataTable without having to create any new variables.

DataTable.DefaultView.Sort = "ColumnName ASC"
DataTable = DataTable.DefaultView.ToTable


ASC - Ascending

DESC - Descending

ColumnName - The column you want to sort by

DataTable - The table you want to sort

~ Answered on 2016-09-29 12:34:36


Try this:

Dim dataView As New DataView(table)
dataView.Sort = " AutoID DESC, Name DESC"
Dim dataTable AS DataTable = dataView.ToTable()

~ Answered on 2012-09-18 08:28:06

Most Viewed Questions: