473,224 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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 9473
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....
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.