2

重複キー違反をキャッチしようとしています。Intellisense ポップアップに System.OleDB.OleDBException が表示されますが、内部例外は null です。System.OleDB.OleDBException のエラー コードにアクセスするにはどうすればよいですか?

グレッグ

try 
{
    MyData.ConExec(sSQL);
}
    catch (Exception ex)
{
OleDbException innerException = ex.InnerException as OleDbException;
if (innerException.ErrorCode == -2147217873)
{
    // handle exception here..
}
else
{
    throw;
}
}
4

1 に答える 1

2

例外のインスタンスを宣言しないでください。そうすれば、必ず空に戻ります。

try
{
    MyData.ConExec(sSQL);
}
catch (OleDbException ex)
{
    // handle excpetion here...

    if (ex.ErrorCode == -2147217873)
    {

    }
}
catch (Exception e)
{
    // if other exception will occur
}
于 2012-12-29T01:06:21.437 に答える