将数据集导出到xml [英] export dataset to xml

查看:80
本文介绍了将数据集导出到xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

设置DataRelation时出现此错误:

Hi everyone,

I get this error when I set DataRelation:

orderProductsRel.Nested = true;


给了我这个错误

我无法继续序列化DataTable的订单详细信息".它包含一个DataRow,该DataRow在同一外键上具有多个父行.

所有代码:


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 =
thisDataset.Relations.Add("custOrders",
thisDataset.Tables["Customers"].Columns["CustomerID"],
thisDataset.Tables["orders"].Columns["CustomerID"]);
custOrderRel.Nested = true;
DataRelation orderDetailRel = thisDataset.Relations.Add("OrderDetali",
thisDataset.Tables["orders"].Columns["orderID"],
thisDataset.Tables["order details"].Columns["orderID"]);
orderDetailRel.Nested = true;
DataRelation orderProductsRel= thisDataset.Relations.Add("OrderProducts",
                   thisDataset.Tables["Products"].Columns["ProductID"],
                   thisDataset.Tables["order details"].Columns["ProductID"]);
orderProductsRel.Nested = true;
thisDataset.WriteXmlSchema("c:\\wsc.xml");
thisDataset.WriteXml("c:\\s.xml");

推荐答案

我认为,这与数据集尝试序列化,试图将子级嵌套在父级中有关,并且在谁是父级方面存在歧义订单详细信息"行中这意味着,如果它已经将订单详细信息嵌套在订单下,那么它也不能将其嵌套在产品下.我建议设置 orderProductsRel.Nested = false;
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;


这篇关于将数据集导出到xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆