怎样在DataSet中建立表间关系

解决方案 »

  1.   

    http://www.cnblogs.com/thcjp/archive/2006/05/03/dataset.html
      

  2.   

    http://aspxboy.com/private/334/default.aspx
      

  3.   

    xiahouwen 还差426分就升四星了,呵呵,先恭喜一下吧~
      

  4.   

    在Dataset对象中有Relation,利用它就可以将表之间建立关连
      

  5.   

    4楼正解,用DataRelation 可以建立表之间的关系
      

  6.   

    DataRelation 到MSDN上找下具体用法
      

  7.   

     string constring = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);
                SqlConnection myconn = new SqlConnection(constring);
                myconn.Open();
                DataSet ds = new DataSet();
                string sql1 = "select * from class where type=1";
                SqlDataAdapter sda1 = new SqlDataAdapter(sql1,myconn);
                sda1.Fill(ds, "parent");
                string sql2 = "select * from class where type=2";
                SqlDataAdapter sda2 = new SqlDataAdapter(sql2, myconn);
                sda2.Fill(ds, "child");            //下面注释的六行代码完全可以被一行代码取代
                //ds.Tables[0].TableName="parent";
                //ds.Tables[1].TableName="child";
                //DataColumn father=ds.Tables["parent"].Columns["id"];
                //DataColumn son=ds.Tables["child"].Columns["pid"];
                //DataRelation myrelation = new DataRelation("myrelation", father,son, false);
                //ds.Relations.Add(myrelation);            ds.Relations.Add("myrelation", ds.Tables["parent"].Columns["id"], ds.Tables["child"].Columns["parentid"]);
                
                dlCategories.DataSource = ds.Tables["parent"].DefaultView;
                dlCategories.DataBind();详细见blog:
    http://blog.csdn.net/yangtzeu/archive/2008/02/19/2105324.aspx
      

  8.   

    DataRelation 建立表之间的关系
      

  9.   

    恭喜xiahouwen四星了~ 散分庆祝一下吧~ 
      

  10.   

    http://epasser.aydc.com.cn/article/search.jsp  你想要的里面都有
      

  11.   

    1.创建DataRelation对象
    2.调用DataSet实例的Relations属性的Add方法以DataRelation对象作为参数