DataTable排序的一般方法
一、重生法
dstaset.Tables.Add(dt)
dataset.Tables(0).DefaultView.Sort = "id desc"
--------------------------------------------------------------------------------
二、直接法
dv = New DataView(dt)
dv.Sort = "id desc"
--------------------------------------------------------------------------------
三、間接法
dv = New DataView(ds.Tables[0])
dv.Sort = "id desc"
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();