Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2009, 12:35 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default NESTED XML USING DATASET

Hi,

I would appreciate if someone could help me to solve this problem.

I am trying to use a dataset to generate nested XML but am getting the following error:

"Cannot proceed with serializing DataTable 'Order Details'. It contains a DataRow which has multiple parent rows on the same Foreign Key."

I had a look at the Northwind database to try and figure out what that message means and I think that the problem is related to the fact that the [Order Detail] table has a composite primary key OrderID and ProductID.

Example :

Customer Orders Order Detail Products
-------------- ---------- ----------------- -------------
CustomerID OrderID OrderID ProductID
ProductID

This is the code I am using to set up the relationship:

DataRelation custOrderRel = thisDataSet.Relations.Add("CustOrders",
thisDataSet.Tables["Customers"].Columns["CustomerID"],
thisDataSet.Tables["Orders"].Columns["CustomerID"]);


DataRelation orderDetailRel = thisDataSet.Relations.Add("OrderDetail",
thisDataSet.Tables["Orders"].Columns["OrderID"],
thisDataSet.Tables["Order Details"].Columns["OrderID"]);

DataRelation orderProductRel = thisDataSet.Relations.Add(
"OrderProducts", thisDataSet.Tables["Products"].Columns["ProductID"],
thisDataSet.Tables["Order Details"].Columns["ProductID"]);

thisDataSet.WriteXmlSchema(Server.MapPath("~/xml/Northwind.xsd"));
thisDataSet.WriteXml(Server.MapPath("~/xml/Northwind.xml"));

thisDataSet.Relations["CustOrders"].Nested = true;
thisDataSet.Relations["OrderDetail"].Nested = true;
thisDataSet.Relations["OrderProducts"].Nested = true;

thisDataSet.WriteXml(Server.MapPath("~/xml/nestedNorthwind.xml"));

Cheers

P.
 
Old March 3rd, 2009, 12:52 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default NESTED XML USING DATASET

I am sorry. The example got messed up.

These are the tables I am using in the dataset

Customer
--------------
CustomerID

+++++++++++++++++++

Orders
----------
OrderID

++++++++++++++++++++

Order Detail
-----------------
OrderID
ProductID

+++++++++++++++++++++

Products
--------------
ProductID

And this is how they are related:

Customer ----> Order

Order -----> Order Detail <---- Products

Thanks

P
 
Old March 4th, 2009, 05:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi pallone,

Never ran into this error so I don't know the fix, but maybe this helps: http://forums.asp.net/p/1079069/1598048.aspx#1598048

Not really a solution, but at least some work around...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 5th, 2009, 06:00 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default NESTED XML USING DATASET

Hi Imar,

Thanks for the reply.

I had seen this before and had tried to set the constraints off but it did not work for me.

Basically, I have a many-to-many relationship between Order and Product via a bridge table called OrderDetail.

The bridge table's primary key consists of two foreign keys coming from each of the corresponding tables.

I need to find a way to set the relations between the tables in the right way. This is really driving me nuts !!!!!!

Cheers

P





Similar Threads
Thread Thread Starter Forum Replies Last Post
Flat XML to nested IgorK XSLT 10 November 24th, 2008 09:56 AM
Convert nested XML to flat one dani1 XSLT 15 October 21st, 2008 02:20 AM
read nested xml into a dataset sansircar ASP.NET 1.0 and 1.1 Professional 0 August 1st, 2006 03:08 PM
Nested XML to CSV transformation 2Poc XSLT 2 September 19th, 2005 03:11 AM
converting self-nested xml to html its_vippy XSLT 1 June 1st, 2005 04:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.