0

我在 SQL 数据库中有两个表。一个表正在引用另一个表。

我正在从 VB.NET 程序的表中添加数据。我想写一个try...catch块来捕获在将数据添加到可能发生违规SQLException的表时抛出的问题。Foreign Key我该怎么写?

4

2 回答 2

1

您可以尝试使用此代码

Try
  ...

Catch ex As Exception
   MsgBox("Your exception" & ex.Message)
End Try

链接:http: //msdn.microsoft.com/fr-fr/library/0yd65esw%28v=vs.80%29.aspx

于 2012-09-20T18:01:21.327 回答
0
 Try
      'Do your stuff
 Catch ex as SqlException
      Dim errors = ex.Errors
      ' inspect errors to decide if this is the condition you want to catch
      Dim shouldCatch As Boolean = ... 
         ' Code that acts on the specific error condition
      If shouldCatch Then
      Else
         Throw ' rethrow everything we're not interested in
      End If
 End Try
于 2012-09-20T18:09:41.217 回答