Handle ConstraintException and get ColumnName that cause the error

Posted by Mysterious on Stack Overflow See other posts from Stack Overflow or by Mysterious
Published on 2010-04-05T10:23:54Z Indexed on 2010/04/05 10:33 UTC
Read the original article Hit count: 321

Hello, I have a Table Machines that made of:
ID = Identity , Primary , AutoIncrement,NOT NULL
SN = Unique , String , NOT NULL Name =String

now I am using a form to insert data into this table, and I am using BindingSource and ErrorProvider, I am handling Null and Empty string in the DataSet layer (partial class in the dataset.xsd),

now when I try to end editing

this.machinesBindingSource.EndEdit();

I got this error message:

ex.Message = "Column 'SN' is constrained to be unique.  Value '123' is already present."

I know I entered a duplicated value but the question is HOW can I determine which the columnName that cause the error and re-write the error message entirely in different language I want to get the columnName and the wrong value

thanks in advance

© Stack Overflow or respective owner

Related posts about dataset

Related posts about errorprovider