Ensuring uniqueness of a record when using a DataSet schema

  • Thread starter Thread starter DotNet Ed
  • Start date Start date
D

DotNet Ed

Ignore the previous post, this dumb OE sent my posting prematurely...

Anyway, the problem is I have an XML schema where I have specified that a
particular element is to be UNIQUE. This schema is read with the DataSet's
ReadXmlSchema() before reading the actual data with ReadXml().
I specified that that particular field is a Primary Key so I see something
like this:

<xs:complexType>...</xs:complexType>
<xs:key name="MyTableKey1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:MyTable" />
<xs:field xpath="mstns:Name" />
</xs:key>

within the complex type there is an <xs:element name="Name" type="string"
.... />

In the dataset I have also set that particular DataColumn as PrimaryKey.

The problem is... that I am able to inject several identical rows in the
data set, so even though the Name field/element is not unique no error is
produced... What am I missing here?

Regards,
Emilio
 
Emilio,

Try and verify that the constraint you have specified (PrimaryKey) after you
have done a ReadXmlSchema; is actually what you expected it to be
(PrimaryKey/UniqueConstraint) as per the XML. You will have to do this in
debug mode on the object after the ReadXmlSchema happens.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 
Back
Top