Answers for "c# duplicate key exception"

C#
1

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
}
Posted by: Guest on March-10-2020

C# Answers by Framework

Browse Popular Code Answers by Language