發(fā)布時(shí)間:2020-08-06 08:57 作者:獨(dú)孤劍 閱讀:1976
static void Main(string[] args) { DataTable dt1 = new DataTable(); dt1.Columns.Add("id", typeof(int)); dt1.Columns.Add("title", typeof(string)); dt1.Columns["id"].AutoIncrement = true; for (int i = 0; i < 100; ++i) { DataRow newRow = dt1.NewRow(); newRow["title"] = DateTime.Now.Ticks.ToString(); dt1.Rows.Add(newRow); } DataTable dt2 = new DataTable(); dt2.Columns.Add("id", typeof(int)); dt2.Columns.Add("title", typeof(string)); dt2.Columns["id"].AutoIncrement = true; for (int i = 0; i < 100; i++) { DataRow newRow = dt2.NewRow(); newRow["title"] = DateTime.Now.Ticks.ToString(); dt2.Rows.Add(newRow); } // dt1合并dt2數(shù)據(jù) dt1.Merge(dt2); // DataTable 排序 dt1.DefaultView.Sort = "id asc"; DataTable dtSort = dt1.DefaultView.ToTable(); }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞