Transection
Dim conn As New SqlConnection(sqlConn)
Dim tr As SqlTransaction
Dim cmd As New SqlCommand
Dim conn As New SqlConnection(sqlConn)
Dim tr As SqlTransaction
Dim cmd As New SqlCommand
Trysqlconn.Open() tr = sqlconn.BeginTransaction()
cmd.Connection = conn
cmd.Transaction = tr
cmd.CommandText = "insert into Table1
(fields1,fields2,fields3) values (" & object1.text & " , " &
object2.text & "," & object3.text &")"cmd.ExecuteNonQuery()
cmd.CommandText = "insert into Table2
(fields1,fields2,fields3) values (" & object1.text & " , "
&object2.text & "," & object3.text &")"
cmd.ExecuteNonQuery()
tr.Commit()
Catch ex As Exceptiontr.Rollback()End Try
Label1.Text = "ERR " & ex.ToString
conn.Close()
ความคิดเห็น