0

使用 Try/Catch 是否可以通过 Msg ID 捕获 MSSQL 错误?我想在找不到表时捕获 208 然后创建它。我在 C# 中找到了模型代码,但对于如何获取错误 ID,VB.NET 却一无所知。

4

1 回答 1

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
于 2012-04-19T14:20:59.870 回答