合併數據Merge

 protected void Page_Load(object sender, EventArgs e)
    {
        DataSet dsSource = new DataSet();        //創建源數據集
        DataSet dsTarget = new DataSet();        //創建目標數據集
        string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
        using (SqlConnection con = new SqlConnection(conStr))//創建數據連接
        {
            //創建數據適配器
            SqlDataAdapter sda = new SqlDataAdapter("select * from DictionaryType", con);
            sda.Fill(dsSource, "DictionaryType");//將字典類添加到源數據集

            sda = new SqlDataAdapter("select * from DictionaryItem", con);
            sda.Fill(dsTarget, "DictionaryItem");//將字典值添加到目標數據集
        }
        dsTarget.Merge(dsSource);   //將源數據集的DictionaryType表合併到目標數據集中
        GridView1.DataSource = dsTarget.Tables["DictionaryType"];
        GridView1.DataBind();
    }
學習下。
轉載自:http://www.cnblogs.com/hsw-2013/archive/2013/03/16/2962451.html
發佈了20 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章