标题:DataRelation问题
只看楼主
panazhiyong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-5-4
 问题点数:0 回复次数:0 
DataRelation问题
SqlConnection cn = new SqlConnection(cnStr);
            ds = new DataSet();

            string sqlStr = "SELECT yxdm, yxmc  FROM  jc_jgb order by yxdm";
           myDataAdapter = new SqlDataAdapter(sqlStr, cn);
            myDataAdapter.Fill(ds, "jc_jgb");

            sqlStr = "SELECT yxdm,jcbh,jcmc,zz,dj FROM jc_kcb order by yxdm,jcmc ";
            myDataAdapter = new SqlDataAdapter(sqlStr, cn);
             myDataAdapter.Fill(ds, "jc_kcb");


            sqlStr = "SELECT  yxdm,zydm,zymc,xz FROM jc_zyb order by yxdm,zydm ";
            myDataAdapter = new SqlDataAdapter(sqlStr, cn);
            myDataAdapter.Fill(ds, "jc_zyb");

 
 


            //DataColumn parentColumn = ds.Tables["jc_jgb"].Columns["yxdm"];
            //DataColumn childColumn = ds.Tables["jc_kcb"].Columns["yxdm"];
            //创建关系
            DataRelation rel_jg_jc = new DataRelation("jg_jc", ds.Tables["jc_jgb"].Columns["yxdm"], ds.Tables["jc_kcb"].Columns["yxdm"]);

            // 添加关系到dataset
            ds.Relations.Add(rel_jg_jc);

            DataRelation rel_jg_zy = new DataRelation("jg_zy", ds.Tables["jc_jgb"].Columns["yxdm"], ds.Tables["jc_zyb"].Columns["yxdm"]);

            // 添加关系到dataset
            ds.Relations.Add(rel_jg_zy);
            

            // 将数据集中的Customers表绑定到DataGrid控件上
            dataGridView2.DataSource = ds.Tables["jc_jgb"].DefaultView;
            dataGridView3.DataSource = ds.Tables["jc_jgb"].DefaultView;
            dataGridView3.DataMember = rel_jg_jc.ToString();
            dataGridView4.DataSource = ds.Tables["jc_jgb"].DefaultView;
            dataGridView4.DataMember = rel_jg_zy.ToString();



请问红色那两句中的绿色的字段是什么来的,怎样定义的?为什么改了它之后就运行出错,谢谢!
2011-11-17 16:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-355498-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057121 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved