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?
.NET ProgrammingVisual Basic.NETC#

Avatar of undefined
Last Comment
brotherbill999

8/22/2022 - Mon
SOLUTION
Daniel Junges

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
Daniel Junges

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
brotherbill999

ASKER
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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck