Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I get this error when I set DataRelation:
orderProductsRel.Nested = true;

gave me this error

I cannot proceed with serializing DataTable 'order details'. It contains a DataRow which has multiple parent rows on the same Foreign Key.

All of the code :
SqlDataAdapter custAdapter = new SqlDataAdapter("select * from Customers",conn);
SqlDataAdapter orderAdapter = new SqlDataAdapter("select * from orders", conn);
SqlDataAdapter detailsAdapter = new SqlDataAdapter("select * from [order details]", conn);
SqlDataAdapter productsAdapter = new SqlDataAdapter("select * from Products",conn);

custAdapter.Fill(thisDataset, "Customers");
orderAdapter.Fill(thisDataset, "orders");
detailsAdapter.Fill(thisDataset, "order details");
productsAdapter.Fill(thisDataset, "Products");
//DataColumn d = new DataColumn();
//d.ColumnName ="orderID";
//d.DataType =(System .Type .st) sqlDbType .Text ;
DataRelation custOrderRel =
custOrderRel.Nested = true;
DataRelation orderDetailRel = thisDataset.Relations.Add("OrderDetali",
thisDataset.Tables["order details"].Columns["orderID"]);
orderDetailRel.Nested = true;
DataRelation orderProductsRel= thisDataset.Relations.Add("OrderProducts",
                   thisDataset.Tables["order details"].Columns["ProductID"]);
orderProductsRel.Nested = true;
Updated 16-Dec-10 21:55pm
JF2015 17-Dec-10 0:37am    
Edited to fix spelling and code formatting.
Dalek Dave 17-Dec-10 3:55am    
Minor Edit for Grammar.

1 solution

I believe this has to do with when the dataset tries to serialize, it attempts to nest the children in the parents, and comes across an ambiguity with regards to who is the parent of the 'order details' rows. Meaning, if it has already nested the order details under the orders, then it cannot also nest it under the products. I would recommend setting the orderProductsRel.Nested = false;
Share this answer
Mostafa Elsadany 17-Dec-10 3:48am    
ok i do
but if a relation in dataset add dynamic so
i don't konw what a last relation to set realtionname.Nested = false;
JOAT-MON 17-Dec-10 4:13am    
It is not because it is the last relationship added, it is because it is the one that is contradictory to the other relationships. If you allow for relationships to be dynamically added, then you will need to do a little validation to make sure that if the relationship is nested, then the specified child does not already have another parent in the Relations property.
Mostafa Elsadany 17-Dec-10 4:23am    
yes thank im sorry
if i leave all relation.Nested = false;
there is any problem
in export to xml
and sorry for my English
JOAT-MON 17-Dec-10 4:33am    
By default, the Nested property is false. I have not had any problems serializing when this is the case. The serializer will simply write out each table individually without trying to nest the rows.
And no need to apologize about the English. :)
Mostafa Elsadany 18-Dec-10 22:42pm    
now i understand you
but order details gave me error because is parent rows on the same Foreign Key
but the Foreign Key on other column
1- ProductID
2- orderID
so how i can solve this
thnx for your time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900