合并数据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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章