原代码:
DataView dv = ds.Tables["NextNode"].DefaultView;
dv.Sort = "NodeID DESC";
修改后代码:
DataTable dt = ds.Tables["NextNode"];
dt.Columns.Add("newNodeID", typeof(int), "Convert(NodeID,'System.Int32')");
DataView dv =dt.DefaultView;
dv.Sort = "newNodeID DESC";
分析:
DataTable dt = ds.Tables["NextNode"];
//首先在DataTable内加一新列,这列的类型转换成需要的类型
//列名, 类型, 赋值
dt.Columns.Add("newNodeID", typeof(int), "Convert(NodeID,'System.Int32')");
DataView dv = dt.DefaultView;// ds.Tables["NextNode"].DefaultView;
//排序根据新列排序
dv.Sort = "newNodeID DESC";