標籤:page color eve idv getc div GridView typeof span
protected void Page_Load(object sender, EventArgs e) { DataSet dsSource = new DataSet(); //建立來源資料集 DataTable dt = CreateDataTable(); //建立本地表 dsSource.Tables.Add(dt); //將建立的本地表添加到來源資料集中 DataSet copyDataSet1 = dsSource.Copy();//複製整個資料集(包含資料) //僅複製來源資料集中表資料被更改的部分 DataSet copyDataSet2 = dsSource.GetChanges(); //僅複製來源資料集中表資料行狀態為添加狀態的部分 DataSet copyDataSet3 = dsSource.GetChanges(DataRowState.Added); //僅複製來源資料集的架構 DataSet copyDataSet4 = dsSource.Clone(); //取得來源資料集中指定表的指定資料 DataRow[] copyRows = dsSource.Tables[0].Select("productCode = ‘0001‘ "); //將取得的資料數組匯入到僅複製架構的資料集表中 DataTable tbSource = copyDataSet4.Tables[0]; foreach (DataRow copyRow in copyRows) { tbSource.ImportRow(copyRow); } GridView1.DataSource = tbSource; GridView1.DataBind(); } private DataTable CreateDataTable() { DataTable dt = new DataTable(); dt.Columns.Add("productCode", typeof(string)); dt.Columns.Add("saleDate", typeof(DateTime)); dt.Columns.Add("saleAmount", typeof(double)); DataRow dr = dt.NewRow(); dr["productCode"] = "0001"; dr["saleDate"] = Convert.ToDateTime("2009-2-1"); dr["saleAmount"] = 1000; dt.Rows.Add(dr); dr = dt.NewRow(); dr["productCode"] = "0001"; dr["saleDate"] = Convert.ToDateTime("2009-1-1"); dr["saleAmount"] = 2000; dt.Rows.Add(dr); dr = dt.NewRow(); dr["productCode"] = "0002"; dr["saleDate"] = Convert.ToDateTime("2009-1-1"); dr["saleAmount"] = 3000; dt.Rows.Add(dr); return dt; }
021. asp.net兩個DataSet資料集的合并