dotConnect for Oracle Documentation
Commit Method
See Also  Example support@devart.com
Devart.Data.Oracle Namespace > OracleConnection Class : Commit Method

Commits the database transaction.

Syntax

Visual Basic (Declaration) 
Public Sub Commit() 
C# 
public void Commit()

Example

The following example demonstrates how to use Commit and Rollback methods.
C#csharpCopy Code
public void RunOracleTransaction(string myConnString)
{
  OracleConnection myConnection = new OracleConnection(myConnString);
  myConnection.Open();
  OracleCommand myCommand = new OracleCommand();
  myCommand.Connection = myConnection;
  myConnection.BeginTransaction();
  try
  {
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')";
    myCommand.ExecuteNonQuery();
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(60, 'PRODUCTION')";
    myCommand.ExecuteNonQuery();
    myConnection.Commit();
    Console.WriteLine("Both records are written to database.");
  }
  catch(Exception e)
  {
    myConnection.Rollback();
    Console.WriteLine(e.ToString());
    Console.WriteLine("Neither record was written to database.");
  }
  finally
  {
    myConnection.Close();
  }
}
C#Visual BasicCopy Code
Public Sub RunOracleTransaction(myConnString As String)
  Dim myConnection As New OracleConnection(myConnString)
  myConnection.Open()
  Dim myCommand As New OracleCommand()
  myCommand.Connection = myConnection
  myConnection.BeginTransaction()
  Try
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
    myCommand.ExecuteNonQuery()
    myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values(60, 'PRODUCTION')"
    myCommand.ExecuteNonQuery()
    myConnection.Commit()
    Console.WriteLine("Both records are written to database.")
  Catch e As Exception
    myConnection.Rollback()
    Console.WriteLine(e.ToString())
    Console.WriteLine("Neither record was written to database.")
  Finally
    myConnection.Close()
  End Try
End Sub

Requirements

Platforms:Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8, Windows 10, Windows Server 2012 family.

See Also