E
Emma Middlebrook
Hi there,
I have created an XmlSchema to represent the tables in my database and
I have specified a primary key for each of the tables.
However, to be able to execute the following code:
DatabaseTables.CategoryInfoRow categoryRow =
m_dtCategories.Rows.Find(selected.category_ID) as
DatabaseTables.CategoryInfoRow;
I need to explicitly reassign the primary keys for the table with this
as it throws an error saying no primary key defined:
// Specify the primary key columns
DataColumn[] keys = new DataColumn[1];
keys[0] = m_dtCategories.Columns["Category_ID"];
m_dtCategories.PrimaryKey = keys;
Can anyone suggest what has gone wrong with my schema or was this
always the way we had to do it? I didn't manually write the xml for the
schema, I did it through setting properties in the data view but here
is what it generated for my table in question:
<xs:element name="CategoryInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Category_ID" type="xs:int"
msdata:AutoIncrement="true" />
<xs:element name="Parent_Cat_ID" type="xs:int" />
<xs:element name="Category_Name" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:key name="PK_CategoryInfo" msdata
rimaryKey="true">
<xs:selector xpath="." />
<xs:field xpath="mstns:Category_ID" />
</xs:key>
</xs:element>
Thanks,
Emma
I have created an XmlSchema to represent the tables in my database and
I have specified a primary key for each of the tables.
However, to be able to execute the following code:
DatabaseTables.CategoryInfoRow categoryRow =
m_dtCategories.Rows.Find(selected.category_ID) as
DatabaseTables.CategoryInfoRow;
I need to explicitly reassign the primary keys for the table with this
as it throws an error saying no primary key defined:
// Specify the primary key columns
DataColumn[] keys = new DataColumn[1];
keys[0] = m_dtCategories.Columns["Category_ID"];
m_dtCategories.PrimaryKey = keys;
Can anyone suggest what has gone wrong with my schema or was this
always the way we had to do it? I didn't manually write the xml for the
schema, I did it through setting properties in the data view but here
is what it generated for my table in question:
<xs:element name="CategoryInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Category_ID" type="xs:int"
msdata:AutoIncrement="true" />
<xs:element name="Parent_Cat_ID" type="xs:int" />
<xs:element name="Category_Name" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:key name="PK_CategoryInfo" msdata

<xs:selector xpath="." />
<xs:field xpath="mstns:Category_ID" />
</xs:key>
</xs:element>
Thanks,
Emma