See Also

OracleConnection Class  | OracleConnection Members  | Overload List  | OracleCommand Class  | OracleTransaction Class  | Commit Method  | Rollback Method


Visual Basic


Show All

See AlsoLanguagesDevart.Data.OracleSend comments on this topic.

BeginTransaction() Method

Devart.Data.Oracle Namespace > OracleConnection Class > BeginTransaction Method : BeginTransaction() Method

Begins a database transaction.

[Visual Basic]
Overloads Public Function BeginTransaction() As OracleTransaction
public OracleTransaction BeginTransaction();

Return Type

An object representing the new transaction.


To commit or roll back the transaction, you must explicitly use the Commit or Rollback methods.


The following example creates a OracleConnection and a OracleTransaction. It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.


public void RunOracleTransaction(string myConnString) 

  OracleConnection myConnection = new OracleConnection(myConnString); 
  OracleCommand myCommand = new OracleCommand(); 
  myCommand.Connection = myConnection; 
  OracleTransaction myTrans; 
  // Start a local transaction 
  myTrans = myConnection.BeginTransaction(); 
  // Assign transaction object for a pending local transaction 
  myCommand.Transaction = myTrans; 
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"; 
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(60, 'PRODUCTION')"; 
    Console.WriteLine("Both records are written to database."); 
  catch(Exception e) 
    Console.WriteLine("Neither record was written to database."); 

[Visual Basic] 

Public Sub RunOracleTransaction(myConnString As String)
  Dim myConnection As New OracleConnection(myConnString)

  Dim myCommand As New OracleCommand()
  myCommand.Connection = myConnection
  Dim myTrans As OracleTransaction

  ' Start a local transaction
  myTrans = myConnection.BeginTransaction()
  ' Assign transaction object for a pending local transaction
  myCommand.Transaction = myTrans

    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(60, 'PRODUCTION')"
    Console.WriteLine("Both records are written to database.")
  Catch e As Exception
    Console.WriteLine("Neither record was written to database.")
  End Try
End Sub

See Also

OracleConnection Class  | OracleConnection Members  | Overload List  | OracleCommand Class  | OracleTransaction Class  | Commit Method  | Rollback Method



© 2002 - 2016 Devart. All Rights Reserved.