發布時間:2020-08-22 06:56 作者:獨孤劍 閱讀:3443
using System; using System.Data; namespace ConsoleApp3 { class Program { 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 < 10; ++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 < 10; i++) { DataRow newRow = dt2.NewRow(); newRow["title"] = DateTime.Now.Ticks.ToString(); dt2.Rows.Add(newRow); } // dt1合并dt2數據 dt1.Merge(dt2); } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞