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.
|