Skip to content

Instantly share code, notes, and snippets.

@ggMartinez
Last active July 16, 2020 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ggMartinez/ab7fea7d8d924e357f337d3183053dea to your computer and use it in GitHub Desktop.
Save ggMartinez/ab7fea7d8d924e357f337d3183053dea to your computer and use it in GitHub Desktop.
Ejemplo Transaccion VB.NET
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