C#怎么给datatable按某行排序
datatable里面有个列是记录时间的,我想根据时间排序,C#里面该怎么写?
------解决方案--------------------DataRow[] rows = dataTable1.Select("", "ord asc");
DataTable t = DataTable1.Clone();
t.Clear();
foreach (DataRow row in rows)
t.ImportRow(row);
DataTable1 = t;
VS2005中这种方法最简单:
DataView dv = dt.DefaultView;
dv.Sort = "c1 Asc";
DataTable dt2 = dv.ToTable();
----
//拿到数据源
DataView dv = this.dtDataSource.Copy().DefaultView;
//排序
dv.Sort = "款 asc,項 asc,目 asc";
//过滤重复数据
//DataTable dt = dv.ToTable(true, "款", "項", "目");
//不过滤重复数据
DataTable dt = dv.Table.Copy();