DataTable 排序

排序DataSet中其中一个表格的数据

且该数据为小数类型

DataSet ds;//为数据源

DataTable dt= ds.Tables[0];//获取第一个表格数据

dt.Columns["Score"].DataType = typeof(decimal);//声明某字段类型

若不声明类型,会出现排序异常问题

如,11  8  1.1  排序会出现  11  1.1  8

dt.DefaultView.Sort = " Score  desc ";//desc为倒序(从大到小)  asc 为正序(从小到大)//Score为你要排序的字段
dt= dt.DefaultView.ToTable();

DataTable Score = ds.Tables["Score"];//分数
Score.Columns["Score"].DataType = typeof(decimal);//如果是字符类型可省略
Score.DefaultView.Sort = "Score desc";
Score = Score.DefaultView.ToTable();

 

posted @ 2023-06-07 16:48  HoFei1113  阅读(78)  评论(0编辑  收藏  举报