我在SQL數據庫中有兩個表。一個表正在引用另一個表。vb.net中的SQLexception
我正在從VB.NET程序的表中添加數據。我想寫一個try...catch
塊來捕獲SQLException
將數據添加到可能發生Foreign Key
衝突的表中。我如何編寫它?
我在SQL數據庫中有兩個表。一個表正在引用另一個表。vb.net中的SQLexception
我正在從VB.NET程序的表中添加數據。我想寫一個try...catch
塊來捕獲SQLException
將數據添加到可能發生Foreign Key
衝突的表中。我如何編寫它?
您可以使用此代碼嘗試
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
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
能告訴你一個例子嗎? –