【发布时间】:2010-06-15 16:40:40
【问题描述】:
在 asp.net(c#) 中,我使用 linqtosql,在表中,我将字段 Isunique 的属性设置为 true.. 当再次插入相同的值时,它显示错误(异常)“无法插入重复键具有唯一索引的对象'dbo.student'中的行”,我需要捕获异常并显示错误消息。如何处理sqlexception?提前谢谢...
【问题讨论】:
标签: c# asp.net linq-to-sql exception
在 asp.net(c#) 中,我使用 linqtosql,在表中,我将字段 Isunique 的属性设置为 true.. 当再次插入相同的值时,它显示错误(异常)“无法插入重复键具有唯一索引的对象'dbo.student'中的行”,我需要捕获异常并显示错误消息。如何处理sqlexception?提前谢谢...
【问题讨论】:
标签: c# asp.net linq-to-sql exception
最简单的形式:
try
{
// Code to attempt insert
}
catch(SqlException ex)
{
// Get error from ex.Message and do something with it
}
【讨论】: