2012-04-19 38 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