How to check for duplicate key violation?

Discussion in 'ASP .Net' started by EC, May 20, 2005.

  1. EC

    EC Guest

    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?
     
    EC, May 20, 2005
    #1
    1. Advertisements

  2. EC

    MasterGaurav Guest

    MasterGaurav, May 20, 2005
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    4
    Views:
    1,022
  2. Replies:
    3
    Views:
    1,055
  3. Felix Roberto

    Batch Insert with duplicate key

    Felix Roberto, Dec 7, 2006, in forum: Java
    Replies:
    3
    Views:
    1,625
    andrewmcdonagh
    Dec 12, 2006
  4. Pete
    Replies:
    2
    Views:
    416
    Phlip
    Apr 15, 2006
  5. Jeff
    Replies:
    1
    Views:
    977
    Konstantinos Pantos
    Apr 11, 2007
  6. monika

    error handling-duplicate key

    monika, Sep 16, 2003, in forum: ASP General
    Replies:
    1
    Views:
    164
    Ray at
    Sep 16, 2003
  7. M P
    Replies:
    1
    Views:
    833
  8. John
    Replies:
    2
    Views:
    316
    Mike Brind
    Jul 8, 2006
Loading...