021. asp.net兩個DataSet資料集的合并

來源:互聯網
上載者:User

標籤: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資料集的合并

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.