Last active
July 16, 2020 01:52
-
-
Save ggMartinez/ab7fea7d8d924e357f337d3183053dea to your computer and use it in GitHub Desktop.
Ejemplo Transaccion VB.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Sub Agregar() | |
Comando.CommandText = "SET AUTOCOMMIT = OFF" | |
Comando.ExecuteNonQuery() | |
Comando.CommandText = "LOCK TABLES PERSONA,PERSONA_TEL READ" | |
Comando.ExecuteNonQuery() | |
Comando.CommandText = "START TRANSACTION" | |
Comando.ExecuteNonQuery() | |
Try | |
Comando.CommandText = "INSERT INTO PERSONA (nombre,apellido,mail,activo) VALUES('" + Me.Nombre + "','" + Me.Apellido + "','" + Me.Mail + "'," + Me.Activo + ")" | |
Comando.ExecuteNonQuery() | |
Dim idNuevo As String | |
Comando.CommandText = "SELECT MAX(id) FROM PERSONA" | |
idNuevo = Comando.ExecuteScalar.ToString() | |
Comando.CommandText = "INSERT INTO PERSONA_TEL VALUES(" + idNuevo + "," + Me.Telefono + ")" | |
Comando.ExecuteNonQuery() | |
Comando.CommandText = "COMMIT" | |
Comando.ExecuteNonQuery() | |
Comando.CommandText = "UNLOCK TABLES" | |
Comando.ExecuteNonQuery() | |
Catch ex As Exception | |
Comando.CommandText = "ROLLBACK" | |
Comando.ExecuteNonQuery() | |
Comando.CommandText = "UNLOCK TABLES" | |
Comando.ExecuteNonQuery() | |
Throw New System.Exception("SE rompio todo al carajo ") | |
End Try | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment