Link to home
Create AccountLog in
Avatar of brotherbill999
brotherbill999

asked on

ado.net dataset unique constraint does not prevent adding/merging rows which violate unique constraint

Using ADO.NET 2.0, added a unique constraint, but not primary key.
I am able to merge in data which violates constraint and then get an exception.
But the damage is done and the unique column has multiple rows with same value.
Also, I can add a new row and violate the unique column constraint.

This does not make sense to me.  Am I missing something?  If not, what is the purpose of unique constraint, and what exactly, does it constrain?
SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of brotherbill999
brotherbill999

ASKER

The problem is that Adding in new rows (with DataSet.Fill) that have duplicates will allow those duplicates to be added in spite of the constraint, then after the rows are added, then throws an exception.  Thus, if you want to add rows that may violate any constraints, this must be done manually, checking that constraints will be satisfied (by searching columns via index) and only then adding the row, otherwise throw an exception.  One may want to validate that all rows can be added successfully before adding in new rows.

To say the least, this is not satisfying, intuitive behavior from Microsoft...
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for the responses.  As I stated before, it is strange that Fill will populate rows in violation of a unique constraint, then throw an exception.