很長一段時間,我試圖只從 oracle raise_application_error 方法中捕獲錯誤訊息。但每次錯誤都會回傳 oracle 錯誤行號和代碼。我只需要收到錯誤訊息。
我的 Oracle 查詢如下:
IF totalAmony IS NOT NULL AND sumAmount IS NULL
THEN
RAISE_APPLICATION_ERROR(-20001, 'Account no cannot be blank');
END IF;
還有我的 C# 代碼:
try
{
// somcode...;
}
catch (OracleException ex)
{
MessageBox.Show(lookAndFeelError, ex.Message, "Title", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
我需要在 Messagebox 中顯示“帳號不能為空”。
uj5u.com熱心網友回復:
您可以依賴Code例外物件的屬性。因此,在您的問題示例中,您可以檢查例外代碼是否等于您要查找的例外,如果是,您可以顯示錯誤訊息。
try
{
// somcode...;
}
catch (OracleException ex)
{
if(ex.Code == -20001) {
MessageBox.Show(lookAndFeelError, ex.Message, "Title", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/338218.html
下一篇:使用SQL中的兩個連接更新表資料
