非常新的.Net。一切正常,直到我将<Tracking>
添加到我的XML文件中:
<Product>
<id>product1</id>
<Name>Product 1</Name>
<Packart>detailimg</Packart>
<TitleFile>detailtitleoriginal</TitleFile>
<Description>Description</Description>
<Ingredients>Ingredients</Ingredients>
<FeedingInstructions>Instructions</FeedingInstructions>
<Analysis>Analysis</Analysis>
<Footer>Footer</Footer>
**<Tracking>Test</Tracking>**
</Product>
我的XSD文件是这样的:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string" />
<xs:element name="Name" type="xs:string" />
<xs:element name="Packart" type="xs:string" />
<xs:element name="TitleFile" type="xs:string" />
<xs:element name="Description" type="xs:string" />
<xs:element name="Ingredients" type="xs:string" />
<xs:element name="FeedingInstructions" type="xs:string" />
<xs:element name="Analysis" type="xs:string" />
<xs:element name="Footer" type="xs:string" />
<xs:element name="Tracking" type="xs:string" /></xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
然后在我的aspx页面中我添加了:
<%=row[ "Tracking"]%>
当我在浏览器中查看该页面时,我收到错误:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Source Error:
Line 19: ds = new System.Data.DataSet();
Line 20: ds.ReadXmlSchema(MapPath("Content/xml/Products.xsd"));
Line 21: ds.ReadXml(MapPath("Content/xml/Products.xml"));
Line 22: Cache.Insert("Products", ds, new System.Web.Caching.CacheDependency(MapPath("Content/xml/Products.xml")),
Line 23: DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration);
Source File: d:\ProductDetails.aspx.cs Line: 21
答案 0 :(得分:1)
快速解决此问题的一种方法是在数据集上禁用EnforceConstraints:
ds.EnforceConstraints = false;
//now you can load the data
更新:显然,这可能会产生不必要的影响。您应该在您的方案中确定是否是这种情况。