Hey guys,
Got a tiny problem that I can't seem to get around. I've got a StudentID field in a Student table, which is generated via an XML file. The DataSet works perfectly except that I can add duplicate StudentIDs to the table.
After closing the application, it writes the new DataSet over the existing one stored in the XML file, and this is some of the output from that file:
<Student StudentID="1" FirstName="asd" LastName="asd" Address="asd" City="asd" Course="11" Email="" Comments="" />
<Student StudentID="1" FirstName="asd" LastName="asd" Address="asd" City="asd" Course="11" Email="" Comments="" />
<Student StudentID="1" FirstName="asd" LastName="asd" Address="asd" City="asd" Course="11" Email="" Comments="" />
As you can see, I've got duplicates in here. I've got the StudentID setup like this in the schema file:
<xs:unique name="StudentKey">
<xs:selector xpath=".//mstns:Student" />
<xs:field xpath="@StudentID" />
</xs:unique>
A new student is added like so:
// Setup a new row for the new student.
DataRow newStudent = registerDataSet.Tables["Student"].NewRow();
...
// Add the new student to the table.
registerDataSet.Tables["Student"].Rows.Add(newStudent);
// Accept the changes.
newStudent.AcceptChanges();
Any ideas as to what I'm missing?
Thanks in advance,
-hellz