locked
Detect Duplicate entry mysql+C# RRS feed

  • Question

  • User2031860760 posted

    I want to know the error code for primary key violation for mysql with c#. Earlier i was using -2147467259 erro code i have read somewhere that this error code is for primary key violation. But this error code is coming for every database exception. How to detect primary key violation in catch.

    Any help would be appreciated. Thank you

    Wednesday, July 3, 2013 7:41 AM

Answers

  • User-1998339254 posted

    Hi,

    You need to check that before execution of that qry..

    SET @iCount=(SELECT COUNT * from table where id=@id)

    I F(@iCount<1)

    BEGIN

    EXECUE the query

    END

    ELSE

    BEGIN

    PRINT........

    END

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 8:08 AM

All replies

  • User-1596463 posted

    Hi, direct_tarun

    Check for primary key violation before database exception.

    Wednesday, July 3, 2013 7:49 AM
  • User2031860760 posted

    cant it be checked by error code... or by any specific exception???

    Wednesday, July 3, 2013 7:52 AM
  • User-1998339254 posted

    Hi,

    You need to check that before execution of that qry..

    SET @iCount=(SELECT COUNT * from table where id=@id)

    I F(@iCount<1)

    BEGIN

    EXECUE the query

    END

    ELSE

    BEGIN

    PRINT........

    END

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 8:08 AM