Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# sql duplicate key exception

try
{
    // Try to insert
}
catch (SqlException exception)
{
    if (exception.Number == 2601) // Cannot insert duplicate key row in object error
    {
        // Handle duplicate key error
        return;                  
    }
    else
        throw; // Throw exception if this exception is unexpected
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sql #duplicate #key #exception
ADD COMMENT
Topic
Name
4+8 =