table doesnt have primary key / xsd problem...

J

jack

using the following xsd code :

<xs:element name="tblUsers">
<xs:complexType>
<xs:sequence>
<xs:element name="UserID" type="xs:int" />
<xs:element name="FullName" type="xs:string" />
<xs:element name="UserName" type="xs:string" />
<xs:element name="Password" type="xs:string" />
<xs:element name="Email" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:unique name="tblUsersKey1" msdata:primaryKey="true">
<xs:selector xpath="." />
<xs:field xpath="mstns:UserID" />
</xs:unique>
</xs:element>

i'm unable to execute this against a dataset loaded with the schema and a
sample xml data file.

theRow = systemDB.Tables["tblUsers"].Rows.Find(theUser.UserID);

Exception Details: System.Data.MissingPrimaryKeyException: Table doesn't
have a primary key.

what am i missing?
 
J

jack

after a good bit of searching, i found one way to deal with it.

systemDB = new DataSet();
systemDB.ReadXmlSchema("db.xsd");
systemDB.ReadXml("db.xml");
x[0] = systemDB.Tables["tblUsers"].Columns["UserID"];
systemDB.Tables["tblUsers"].PrimaryKey = x;

this accomplishes the goal... But to avoid having to hard portions of the
schema into the app I need to find a way of embedding the PK within the xsd
file. Any suggestions?
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top