如何取得DataSet中表table0中某记录相关的表table1中相关的记录

leohuang 2004-12-07 04:48:34
如题.多谢!
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
leohuang 2004-12-07
  • 打赏
  • 举报
回复
多谢二位
welshem 2004-12-07
  • 打赏
  • 举报
回复
先要建立关系
例:
DataRelation custOrderRel = custDS.Relations.Add("CustOrders", custDS.Tables[0].Columns["主键名"], custDS.Tables[1].Columns["外键名"]);
foreach (DataRow custRow in custDS.Tables[0].Rows)
{
Console.WriteLine(custRow["要输出的字段"]);
foreach (DataRow orderRow in custRow.GetChildRows(custOrderRel))
Console.WriteLine(orderRow["子表中字段"]);
}
longqiaoman 2004-12-07
  • 打赏
  • 举报
回复
做成主子表,加入主表是table0,子表是Table1
把主表和子表的信息读取到一个记录集ds中

想获取主表table0的行drParent的所有相关的字表记录

DataRow []drChilds=drParent.GetChildRows(ds.Tables[0].ChildRelations[0]);

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧