【问题标题】:Retrieving error codes from SQLite when using ExecuteNonQuery()使用 ExecuteNonQuery() 时从 SQLite 检索错误代码
【发布时间】:2012-06-28 16:45:32
【问题描述】:

在我的 C# 项目中,我使用的是从 CodeProject 下载的 System.Data.SQLite.dll

我的问题是标题-调用SqliteCommand.ExecuteNonQuery()函数后如何获取错误代码?

SQLITE_CONSTRAINT, SQLITE_BUSY, SQLITE_LOCKED等错误码如图here

【问题讨论】:

    标签: c# sqlite system.data.sqlite executenonquery


    【解决方案1】:

    使用 Exception.StackTrace 或 SQLiteException.ErrorCode

    try
    {
    
    }
    catch(SQLiteException ex)
    {
        string code = ex.ErrorCode;
    }
    

    【讨论】:

      【解决方案2】:

      好问题。 System.Exception 没有名为“.ErrorCode”的成员

          Catch Ex As SQLiteException
              E = Ex.ResultCode
              Return E
          End Try
      

      【讨论】:

        【解决方案3】:

        如果您使用 .NET 进行开发,我将对此进行补充以帮助其他人。使用

        SQLiteErrorCode枚举测试结果,投下ErrorCode:

        try
        {
        
        }
        catch(SQLiteException ex)
        {
            SQLiteErrorCode sqlLiteError= (SQLiteErrorCode)ex.ErrorCode;
        
            //Do whatever logic necessary based of the error type
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-04-01
          • 1970-01-01
          • 2011-04-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-01-09
          • 1970-01-01
          相关资源
          最近更新 更多