zoukankan      html  css  js  c++  java
  • ADO:DataSet合并两张表( ds.Merge(ds1))

    原文发布时间为:2008-08-01 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;


    using System.Data.SqlClient;

    public partial class dataset2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["pubsConn"].ConnectionString);
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = new SqlCommand("select title_id,title,type from titles", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "t1");

            UniqueConstraint uc = new UniqueConstraint("pk", ds.Tables["t1"].Columns["title_id"], true);
            ds.Tables["t1"].Constraints.Add(uc);//表必须设主键,不然会直接合并到表的下面

            DataSet ds1 = new DataSet();
            sda.SelectCommand=new SqlCommand("select title_id,ord_num from sales",conn);
            sda.Fill(ds1,"t1");

           Session["ds"]=ds;
            Session["ds1"]=ds1;

            GridView1.DataSource=ds.Tables["t1"];
            GridView1.DataBind();
        
            GridView2.DataSource=ds1.Tables["t1"];
            GridView2.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet ds = (DataSet)Session["ds"];
            DataSet ds1 = (DataSet)Session["ds1"];

           ds.Merge(ds1);//合并

            GridView3.DataSource = ds.Tables["t1"];
            GridView3.DataBind();       
        }
    }

  • 相关阅读:
    java八大数据类型
    变量,常量,作用域
    位运算符
    可变参数
    重写
    javascript中各种循环总结
    前端高效emmit快捷键
    移动端列表页布局
    sublime text3中添加插件CSScomb方法
    友元类头文件互相包含问题
  • 原文地址:https://www.cnblogs.com/handboy/p/7141576.html
Copyright © 2011-2022 走看看