如何捕获与REFERENCE约束FK冲突的语句

时间:2016-10-14 15:25:28

标签: c# mysql exception

statement conflicted with the REFERENCE constraint

我想知道如何捕获此错误消息的异常。 我试图从表中删除一条记录,但该表从另一个表中有一个FK。 提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

try
{
     //Your code block to delete the record.
}
catch(Exception ex)
{
     if (ex.Message.ToLower().Contains("statement conflicted with the reference constraint"))
     {
          //Show custom error message as "need to delete parent value before delete this record."
     }
}