Best way to bind commands to transactions
Is this a correct way of assigning commands to a transaction in ado.net?
Connection.Open()
Command.Transaction = Connection.BeginTransaction()
Try
Command.CommandText = "DELETE FROM table1 WHERE ID = @id "
Command.Parameters.Add("@id", sID)
Command.ExecuteNonQuery()
Command.CommandText = "INSERT INTO table2( blah) VALUES( @blah )"
Command.Parameters.Add("@blah", 111).DbType = DbType.Int64
Command.ExecuteNonQuery()
Command.Transaction.Commit()
Catch ex As Exception
Command.Transaction.Rollback()
Throw New Exception( ex.Message, ex)
Finally
Command.Parameters.Clear()
Connection.Close()
Connection.Dispose()
Command.Dispose()
End Try
Or do i need to create two different command instances one for each DML string and then seperately assign them to the Transaction?
Thanks
|