zoukankan      html  css  js  c++  java
  • C# Datatable排序

    在C#中要对Datatable排序,可使用DefaultView的Sort方法。先获取Datatable的DefaultView,然后设置得到的Dataview的sort属性,最后用视图的ToTable方法将排好序的dataview导出为Datatable。
    代码如下:

     1 DataTable dt = new DataTable();
     2 dt.Columns.Add("ID", typeof(int));
     3 dt.Columns.Add("Name", typeof(string));
     4 
     5 dt.Rows.Add(new object[] { 12, "lwolf" });
     6 dt.Rows.Add(new object[] { 100,"kkkkk"});
     7 dt.Rows.Add(new object[] { 19,"jim" });
     8 dt.Rows.Add(new object[] { 1,"test" });
     9 
    10 DataTable dtCopy = dt.Copy();
    11 
    12 DataView dv = dt.DefaultView;
    13 dv.Sort = "ID";
    14 dtCopy = dv.ToTable();

    这样子最后得到的就是排好序的Datable了。

  • 相关阅读:
    Python-Matplotlib 12 多图figure
    Python-Matplotlib 11 子图-subplot
    Python Day16
    Python Day15
    Python Day13-14
    Python Day12
    Python Day11
    Python Day9-10
    Python Day8
    Python Day8
  • 原文地址:https://www.cnblogs.com/xyyt/p/3488588.html
Copyright © 2011-2022 走看看