How to check for duplicate key violation?

E

EC

I get an SqlException caused by trying to insert a duplicate key into a
table. The user needs to be informed and asked to supply a new input. I
check the SqlException object and see these two properties:

ex.Number = 2627
ex.Message = "Violation of UNIQUE KEY constraint ..."

So is it safe to check the Number property against 2627 ? If not, what is
the proper way to check this exception?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top