Skip Headers

Oracle® Objects for OLE Developer's Guide
10g Release 1 (10.1)

Part Number B10118-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Feedback

BeginTrans Method Example

This example demonstrates the use of BeginTrans to group a set of dynaset edits into a single transaction and Rollback to cancel those changes. Copy this code into the definition section of a form. Then press F5.

Sub Form_Load ()

'Declare variables

Dim OraSession As OraSession

Dim OraDatabase As OraDatabase

Dim OraDynaset As OraDynaset

Dim fld As OraField

'Create the OraSession Object.

Set OraSession = CreateObject("OracleInProcServer.XOraSession")

'Create the OraDatabase Object by opening a connection to Oracle.

Set OraDatabase = OraSession. OpenDatabase("ExampleDb",

"scott/tiger", 0&)

'Create the OraDynaset Object.

Set OraDynaset = OraDatabase.CreateDynaset("select * from emp", 0&)

'Start Transaction processing.

OraSession.BeginTrans

'Setup a field object to save object references.

Set fld = OraDynaset.Fields("sal")

'Traverse until EOF is reached, setting

'each employees salary to zero.

Do Until OraDynaset.EOF = True

OraDynaset.Edit

fld.value = 0

OraDynaset.Update

OraDynaset.MoveNext

Loop

MsgBox "All salaries set to ZERO."

'Currently, the changes have NOT been committed

'to the database.

'End Transaction processing.

'Using RollbackTrans means the rollback can

'be canceled in the Validate event.

OraSession.Rollback

'MsgBox "Salary changes rolled back."

End Sub