在我的C#项目中,我正在使用从System.Data.SQLite.dll
下载的CodeProject。
我的问题是根据标题 - 如何在调用SqliteCommand.ExecuteNonQuery()
函数后获取错误代码?
错误代码,如SQLITE_CONSTRAINT, SQLITE_BUSY, SQLITE_LOCKED
,如here所示。
使用Exception.StackTrace或SQLiteException.ErrorCode
try
{
}
catch(SQLiteException ex)
{
string code = ex.ErrorCode;
}
如果你在.NET中开发,我将添加到这个来帮助其他人。使用
SQLiteErrorCode
枚举来测试结果,强制转换ErrorCode:
try
{
}
catch(SQLiteException ex)
{
SQLiteErrorCode sqlLiteError= (SQLiteErrorCode)ex.ErrorCode;
//Do whatever logic necessary based of the error type
}
好问题。 System.Exception没有名为“.ErrorCode”的成员
Catch Ex As SQLiteException
E = Ex.ResultCode
Return E
End Try