DevExpress控件GridControl如何绑定主从表,具体如何设置?
问题补充:1.请不要到网上搜一些例子直接粘贴给我,发这个帖子我基本上都找遍了,实在是没办法了请您认真回答,回答的好的我会主动加分的谢谢2.我自己也做了一个实验但是明细数据...
问题补充:
1.请不要到网上搜一些例子直接粘贴给我,发这个帖子我基本上都找遍了,实在是没办法了
请您认真回答,回答的好的 我会主动加分的 谢谢
2.我自己也做了一个实验 但是 明细数据没法显示出来
如插入的图
3.贴上我的代码
------------------代码开始----------------------------------------------------------------------
DataSet ds = new DataSet();
string strConn = "User ID=system;Data Source=oracle09;Persist Security Info=True;Password=eport";
OracleConnection conn = new OracleConnection(strConn);
conn.Open();
OracleDataAdapter oda = new OracleDataAdapter("select * from offline_dec.USERINFO", conn);
oda.Fill(ds, "userInfo");
BindingSource bsmaster = new BindingSource();
OracleDataAdapter odaMembers = new OracleDataAdapter("select * from offline_dec.USERINFO_FAMILYMEMBERS", conn);
oda.Fill(ds, "memberInfo");
BindingSource bsSonsMembers = new BindingSource();
OracleDataAdapter odaPlaces = new OracleDataAdapter("select * from offline_dec.USERINFO_WORKPLACE", conn);
oda.Fill(ds, "placeInfo");
BindingSource bsSonsPlaces = new BindingSource();
conn.Close();
//添加约束 家庭成员
DataRelation drMembers = new DataRelation("家庭成员", ds.Tables["userInfo"].Columns["userid"], ds.Tables["memberInfo"].Columns["userid"]);
ds.Relations.Add(drMembers);
//工作地
DataRelation drPlaces = new DataRelation("工作地", ds.Tables["userInfo"].Columns["userid"], ds.Tables["placeInfo"].Columns["userid"]);
ds.Relations.Add(drPlaces);
bsmaster.DataSource = ds;
bsmaster.DataMember = "userInfo";
bsSonsMembers.DataSource = ds;
bsSonsMembers.DataMember = "memberInfo";
bsSonsPlaces.DataSource = ds;
bsSonsPlaces.DataMember = "placeInfo";
gridControl1.DataSource = ds.Tables["userInfo"];
-------------------代码结束-------------------------------------------------------------------------- 展开
1.请不要到网上搜一些例子直接粘贴给我,发这个帖子我基本上都找遍了,实在是没办法了
请您认真回答,回答的好的 我会主动加分的 谢谢
2.我自己也做了一个实验 但是 明细数据没法显示出来
如插入的图
3.贴上我的代码
------------------代码开始----------------------------------------------------------------------
DataSet ds = new DataSet();
string strConn = "User ID=system;Data Source=oracle09;Persist Security Info=True;Password=eport";
OracleConnection conn = new OracleConnection(strConn);
conn.Open();
OracleDataAdapter oda = new OracleDataAdapter("select * from offline_dec.USERINFO", conn);
oda.Fill(ds, "userInfo");
BindingSource bsmaster = new BindingSource();
OracleDataAdapter odaMembers = new OracleDataAdapter("select * from offline_dec.USERINFO_FAMILYMEMBERS", conn);
oda.Fill(ds, "memberInfo");
BindingSource bsSonsMembers = new BindingSource();
OracleDataAdapter odaPlaces = new OracleDataAdapter("select * from offline_dec.USERINFO_WORKPLACE", conn);
oda.Fill(ds, "placeInfo");
BindingSource bsSonsPlaces = new BindingSource();
conn.Close();
//添加约束 家庭成员
DataRelation drMembers = new DataRelation("家庭成员", ds.Tables["userInfo"].Columns["userid"], ds.Tables["memberInfo"].Columns["userid"]);
ds.Relations.Add(drMembers);
//工作地
DataRelation drPlaces = new DataRelation("工作地", ds.Tables["userInfo"].Columns["userid"], ds.Tables["placeInfo"].Columns["userid"]);
ds.Relations.Add(drPlaces);
bsmaster.DataSource = ds;
bsmaster.DataMember = "userInfo";
bsSonsMembers.DataSource = ds;
bsSonsMembers.DataMember = "memberInfo";
bsSonsPlaces.DataSource = ds;
bsSonsPlaces.DataMember = "placeInfo";
gridControl1.DataSource = ds.Tables["userInfo"];
-------------------代码结束-------------------------------------------------------------------------- 展开
2个回答
展开全部
//在YBID和BZYBID之间创建关系
System.Data.DataRelation dataRelation;
System.Data.DataColumn dataColumn1;
System.Data.DataColumn dataColumn2;
dataColumn1 = ds.Tables["Parents"].Columns["YBID"];//设定表关系
dataColumn2 = ds.Tables["Sons"].Columns["BZYBID"];
dataRelation = new System.Data.DataRelation("ParentsSons", dataColumn1, dataColumn2);
if (ds.Relations.Count == 0)
{
ds.Relations.Add(dataRelation);
}
System.Data.DataRelation dataRelation;
System.Data.DataColumn dataColumn1;
System.Data.DataColumn dataColumn2;
dataColumn1 = ds.Tables["Parents"].Columns["YBID"];//设定表关系
dataColumn2 = ds.Tables["Sons"].Columns["BZYBID"];
dataRelation = new System.Data.DataRelation("ParentsSons", dataColumn1, dataColumn2);
if (ds.Relations.Count == 0)
{
ds.Relations.Add(dataRelation);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询