DataSet.ReadXmlSchema() throw DataException - HELP!!!

G

Guest

I have an XML schema which is loaded into a Dataset object.
This schema contain keys and relations as posted here - the MySchema.xsd:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="DataBase.xsd" xmlns:mstns="DataBase.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
targetNamespace="DataBase.xsd"
elementFormDefault="qualified" attributeFormDefault="qualified" id="DataBase">
<xs:element name="EvsDB" msdata:IsDataSet="true"
msdata:EnforceConstraints="True">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Subject" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Defects" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Defect" type="Defect" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Sectors" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element name="Sector" type="Sector" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ID" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="Sector_Defect">
<xs:complexType>
<xs:sequence>
<xs:element name="SectorKey" type="xs:long" />
<xs:element name="DefectKey" type="xs:long" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="SectorKey" msdata:primaryKey="true">
<xs:selector xpath=".//mstns:Sector" />
<xs:field xpath="mstns:ID" />
</xs:key>
<xs:key name="DefectKey" msdata:primaryKey="true">
<xs:selector xpath=".//mstns:Defect" />
<xs:field xpath="mstns:ID" />
</xs:key>
<xs:keyref name="DefectToSector" refer="DefectKey">
<xs:selector xpath=".//mstns:Sector_Defect" />
<xs:field xpath="mstns:DefectKey" />
</xs:keyref>
<xs:keyref name="SectorToDefect" refer="SectorKey">
<xs:selector xpath=".//mstns:Sector_Defect" />
<xs:field xpath="mstns:SectorKey" />
</xs:keyref>
</xs:element>
<xs:complexType name="Defect">
<xs:sequence>
<xs:element name="ID" type="xs:long" msdata:Caption="ID" />
<xs:element name="Type" type="xs:string" msdata:Caption="Type" />
<xs:element name="Sector" type="xs:long" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Sector">
<xs:sequence>
<xs:element name="ID" type="xs:long" msdata:Caption="Name"
msdata:AutoIncrement="true" msdata:AutoIncrementSeed="0"
msdata:AutoIncrementStep="1" />
<xs:element name="Type" type="xs:string" msdata:Caption="Type" />
<xs:element name="Defect" type="xs:long" msdata:Caption="Contain Defect" />
</xs:sequence>
</xs:complexType>
</xs:schema>

But when I load the schema into the DatsSet using:
DataSet ds = new DataSet();
ds.ReadXmlSchema("MySchema.xsd"); // THROW AN EXCEPTION !!!

I get a System.Data.DataException: Invalid 'Key' node inside constraint
named: DefectToSector.

Can anybody tell why?
 
G

Guest

Sorry, I think I didn't posted the exact data as I should.

I'm not using the DataSet directly. I letting the VS 2003 to generate a
DataSet, so it creates e EvsDB class that derived from DataSet. So the real
code that throw the exception is:

EvsDB db = new EvsDB();
db.ReadXmlSchema("EvsDB.xsd"); // THROW AN EXCEPTION !!!

I hope is explain it now.
 
G

Guest

There is no need to read the schema? Since the VS 2003 is already used to
generate a typed dataset, there is no need to read the schema again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top