【问题标题】:In asp.net (c#),storing value to database(linqtosql),sqlexception在asp.net(c#)中,将值存储到数据库(linqtosql),sqlexception
【发布时间】:2010-06-15 16:40:40
【问题描述】:

在 asp.net(c#) 中,我使用 linqtosql,在表中,我将字段 Isunique 的属性设置为 true.. 当再次插入相同的值时,它显示错误(异常)“无法插入重复键具有唯一索引的对象'dbo.student'中的行”,我需要捕获异常并显示错误消息。如何处理sqlexception?提前谢谢...

【问题讨论】:

    标签: c# asp.net linq-to-sql exception


    【解决方案1】:

    最简单的形式:

    try
    {
        // Code to attempt insert
    }
    catch(SqlException ex)
    {
        // Get error from ex.Message and do something with it
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 2011-02-13
      • 1970-01-01
      相关资源
      最近更新 更多