How to get values ​​of excluded unique constraints of Exception in C #?

I have a UniqueConstraint setting for two columns of my datatable.

dtContacts.Constraints.Add(new UniqueConstraint(new DataColumn[] 
{ 
  dtContacts.Columns["Last Name"], 
  dtContacts.Columns["First Name"] ]
}
));

So, when a ConstraintException occurs, I get the following message:

"Column" Last name, first name "limited to a unique value." Grant, Alex is "already present"

Generated by pretty standard code:

MessageBox.Show(e.Message); 

Is there a way to get the specific values ​​that caused the exception? I need to get "Grant, Alex" so I can build my own message.

+4
source share

Source: https://habr.com/ru/post/1621366/


All Articles