Sorting a Data Table

后端 未结 5 1877
借酒劲吻你
借酒劲吻你 2020-12-01 17:47

I tried to sort a data table with following two ways

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

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


        
5条回答
  •  -上瘾入骨i
    2020-12-01 18:33

    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
    

    Where:

    ASC - Ascending

    DESC - Descending

    ColumnName - The column you want to sort by

    DataTable - The table you want to sort

提交回复
热议问题