Tutorial Cara Penggunaan BeginTransaction, Commit, Rollback di VB.NET
Sebenarnya ini merupakan kelanjutan dari Bagian 1 dan 2, yaitu cara menggunakan BeginTrans, CommitTrans, RollbackTrans. Sekarang saya akan share bagaimana pengggunaannya di vbnet, langsung saja ya ini dia contoh sintak penyimpanan data :
Private Sub Cmd_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmd_Save.ClickOn Error GoTo Salah
Dim IsConError As Boolean
Dim conTransaction As SqlClient.SqlTransaction
conTransaction = con.BeginTransaction
IsConError = True
Dim cmd As New SqlClient.SqlCommand("INSERT INTO TMASTER (ID,NAME) VALUES ('" & TxtID.Text & "', '" & TxtName.Text & "'", con)
cmd.ExecuteNonQuery()
conTransaction.Commit()
IsConError = False
MessageBox.Show("Data Tersimpan !", "Info")
Exit Sub
Salah:
Select Case IsConError
Case True
conTransaction.Rollback()
Case Else
MessageBox.Show(Err.Number & " : " & Err.Description, "Test Error Handler")
End Select
End Sub
Tags:
error incorrect syntax near ' ', error incorrect format unknown tag, error cannot insert duplicate key row in object with unique index, error cannot insert the value null into column id table, error violation of primary key constraint cannot insert duplicate key in object, error could not find output table, error No transaction is active, error Object required
Posting Komentar untuk "Tutorial Cara Penggunaan BeginTransaction, Commit, Rollback di VB.NET"