Live2D 看板娘 / Demo

.net DataTable 排序

        System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("One", typeof(System.Int32));
            dt.Columns.Add("Two", typeof(System.Int32));
            DataRow dr = dt.NewRow();
            dr["One"] = 3;
            dr["Two"] = 6;
            DataRow dr1 = dt.NewRow();
            dr1["One"] = 2;
            dr1["Two"] = 4;
            DataRow dr2 = dt.NewRow();
            dr2["One"] = 1;
            dr2["Two"] = 5;
            dt.Rows.Add(dr);
            dt.Rows.Add(dr1);
            dt.Rows.Add(dr2);
            System.Data.DataView dv = dt.DefaultView;
            dv.Sort = "One"; //从小到大
            System.Data.DataTable dt1 = dv.ToTable();
            foreach (System.Data.DataRow varDr in dt1.Rows)
            {
                Response.Write(varDr["One"].ToString() + " " + varDr["Two"].ToString() + "</br>");
            }

 

     System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("One", typeof(System.Int32));
            dt.Columns.Add("Two", typeof(System.Int32));
            DataRow dr = dt.NewRow();
            dr["One"] = 3;
            dr["Two"] = 6;
            DataRow dr1 = dt.NewRow();
            dr1["One"] = 2;
            dr1["Two"] = 4;
            DataRow dr2 = dt.NewRow();
            dr2["One"] = 1;
            dr2["Two"] = 5;
            dt.Rows.Add(dr);
            dt.Rows.Add(dr1);
            dt.Rows.Add(dr2);
            DataRow[] drs = dt.Select(" ", "One DESC "); // 从大到小
            foreach (System.Data.DataRow varDr in drs)
            {
                Response.Write(varDr["One"].ToString() + " " + varDr["Two"].ToString() + "</br>");
            }

 

posted @ 2016-09-22 16:19  MChuang  阅读(625)  评论(0编辑  收藏  举报