after you read the xml into a DataSet, create a relationship between user table and grade table, then add a column to your grade table, set this column's Expression as "parent.name"
fix your grade table, don't put data like average grade in it or add a user with id of 0
TO: saucer(思归, MS .NET MVP) 如果在数据库中执行如下的SQL语句是可以行到想要的结果的.RIGHT OUTER JOIN 那么可以从grade 表中得到所有的数据! SELECT a.name,b.* FROM [user] a RIGHT OUTER JOIN grade b ON a.id = b.userid 是否可以肯定或意味在XML作为数据存贮搞不定这个呢?是否可以肯定要用数据库.
I could be wrong, but as far as I know, it is not possible to do outer join in DataSet, you have to create a column in grade table and manually go through its rows and add name to it
哎,劳烦各位大哥了,怪我自己不看重载的参数列表..可以不要约束主键的! relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol,false); 多谢了!!
ds.Relations.Add("theRel",ds.Tables["user"].Columns["userid"],ds.Tables["grade"].Columns["userid"]);
然后循环user表的Rows
foreach( DataRow row in ds.Tables["user"].Rows )
{
DataRows childRows = row.GetChildRows("theRel");
//比方张三,这里就得到id为1、2、4的三条记录,李四则得到id为3的记录
//然后把这些记录Copy到一个新的Table中
}上面的代码只是简单的示例,没有验证,也许有错,不过我的思路是这样,不知还有没有更方便的方法。
先多谢你俩热心的回答.按你们的办法对于有对应主键时是成功的是应可行的.但对于松散的数据结构如下:
应如何做?
XML中有两表,结构如下:
TABLE user
字段: id,name,
数据: 1 张三
2 李四
TABLE grade
字段 id,userid,value
数据 1 1 90
2 1 80
3 2 70
4 1 94
5 0 94如何在DATASET中得到如下的一个关联视图
vtable
id, userid, name, value
1 1 张三 90
2 1 张三 80
3 2 李四 70
4 1 张三 94
5 0 94
注:数据是在一个XML文件中的!
当数据为上面时ds.Relations.Add("theRel",ds.Tables["user"].Columns["id"],ds.Tables["grade"].Columns["userid"]);
//这句执行不成功!!!!!!!!!!!!!!
如果在数据库中执行如下的SQL语句是可以行到想要的结果的.RIGHT OUTER JOIN 那么可以从grade 表中得到所有的数据!
SELECT a.name,b.* FROM [user] a RIGHT OUTER JOIN grade b ON a.id = b.userid
是否可以肯定或意味在XML作为数据存贮搞不定这个呢?是否可以肯定要用数据库.
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol,false);
多谢了!!