尝试在数据库操作中捕获
你可以使用 Try..Catch 通过将回滚语句放在 Catch Segment 来回滚数据库操作。
Try
'Do the database operation...
xCmd.CommandText = "INSERT into ...."
xCmd.ExecuteNonQuery()
objTrans.Commit()
conn.Close()
Catch ex As Exception
'Rollback action when something goes off
objTrans.Rollback()
conn.Close()
End Try