2012-04-19 44 views
0

Try/Catch有沒有辦法通過Msg ID捕獲MSSQL錯誤?當我找不到表格時,我想捕捉208,然後創建它。我在C#中找到了模型代碼,但沒有明白VB.NET如何獲取錯誤ID。在Msg ID上捕獲錯誤#

回答

0

也許是這樣的:

Try 
    'Some statment 
Catch sqlEx as SqlException When sqlEx.Number = [SQL error number] 
    'Some error handling for that exception 
Catch sqlEx as SqlException When sqlEx.Number = [Another SQL error number] 
    'Some other handling for that exception 
Catch sqlEx as SqlException 
    'Do something else for the other sql exceptions 
Catch ex as Exception 
    Throw 'if there is another exception it might be a good idé to retrow it 
End Try 
+0

@AmanadaSmith:記住最多投票選出您認爲是很好的答案。這給了我們一種溫暖的模糊感覺:P – Arion 2012-04-19 14:40:15