使用Try / Catch有没有办法通过Msg ID捕获MSSQL错误?我想在找不到表时捕获208,然后创建它。我在C#中找到了模型代码,但没有任何关于如何获取错误ID的VB.NET。
答案 0 :(得分: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