📜  c# sql 重复键异常 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:13.689000             🧑  作者: Mango

代码示例1
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
}