DataTable allowing duplicate Entries!?

  • Thread starter Thread starter TJO
  • Start date Start date
T

TJO

I have a typed DataTable with two only fields that, together, I have set as
the key. Why then is the DataTable allowing duplicate entries?
 
You might check the xml (in designer select XML) and codebehind (the actual
cs generated file - InitClass method for *TableName*DataTable class)
generated for dataset.
 
I had to programaticlly add the UniqueConstraint to the table then Enforce
it.
Seems odd that the GUI desinger does not do this for you once you set the
keys.... oh well!
 
I set the key in the DataSet designer in Visual Studio by clicking the table
then in the properties choose the "key" collection and add my columns. This
process did not work for preventing the duplicate entries.

It was only until I programmed the UniqueConstraint did the duplicates
entries stop. I am surprised it works for you without the code. Am I
missing someing in the properties pane? The keys and UniqueConstraint
appear to be separate animals.
 
Hi TJO,

I see. It seems that this property is ignored by code generator.
This is the way to add key in designer: right click on table and select
Add/New Key... (and Edit/Delete key).
The difference I see that the later way creates constraint at dataset level
while your method adds it at datatable level (see source XML).
 
Back
Top