473,467 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

One or more rows contain values violating non-null, unique, or foreign-key constraints

Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from it,
and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates against
the schema, and the dataset was generated from the same schema.

Exception------------------------------------------------------------------------------:
System.Data.ConstraintException: Failed to enable constraints. One or more
rows contain values violating non-null, unique, or foreign-key constraints.
at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema--------------------------------------------------------------------------------:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1" minOccurs="1"
/>
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded" minOccurs="1"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1" minOccurs="1"
/>
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-----------------------------------------------------------------------------------:
<Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code-----------------------------------------------------------------------------------:
public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated here.
...
Nov 12 '05 #1
2 9483
What version of the .NET framework are you using?

"Jeremy Chapman" <me@here.com> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from it, and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates against
the schema, and the dataset was generated from the same schema.

Exception-------------------------------------------------------------------
-----------: System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema----------------------------------------------------------------------
----------: <?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1" minOccurs="1" />
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1" /> <xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-------------------------------------------------------------------------
----------: <Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code------------------------------------------------------------------------
-----------: public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated here.
...

Nov 12 '05 #2
1.1 service pack 1
"Zafar Abbas" <so*****@somewhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
What version of the .NET framework are you using?

"Jeremy Chapman" <me@here.com> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from

it,
and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates
against
the schema, and the dataset was generated from the same schema.

Exception-------------------------------------------------------------------
-----------:
System.Data.ConstraintException: Failed to enable constraints. One or

more
rows contain values violating non-null, unique, or foreign-key

constraints.
at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema----------------------------------------------------------------------
----------:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1"

minOccurs="1"
/>
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1"

/>
<xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded"

minOccurs="1"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1"

minOccurs="1"
/>
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-------------------------------------------------------------------------
----------:
<Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code------------------------------------------------------------------------
-----------:
public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated
here.
...


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: grumfish | last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code: connection = MySQLdb.connect(host="localhost", user="root", passwd="pw", db="japanese") cursor = connection.cursor()...
1
by: Yama | last post by:
Hi, I am really confused. I have created a strong typed dataset for Northwind database Customer table. Now I am loading it with a stream of XML (ADO style) with the following: Customers _cust...
5
by: mm nn | last post by:
Hi, I want to create a table like this: ID Autonum Datefld Date Cat Text Itm Text tCount Number
40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
0
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain...
9
by: JFB | last post by:
Hi All, I have a edit flexgrid, after to fill with different rows manually. How can I insert the rows of my flexgrid to my table (sql server) using ado.net? Any example? I can insert one row...
31
by: One Handed Man \( OHM - Terry Burns \) | last post by:
My Brain is dead !!!!! I modify a single row in a DataTable By setting the FirstName column in a specific row to another name. ( Without Accepting Changes ). However, this statement still...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
0
by: Jeff | last post by:
hi there ;) asp.net 2.0 I'm having problem with paging in GridView, I'm using custom paging. The ObjectDataSource reads in the rows needed for displaying each page as each page is selected....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.