dotConnect for SQLite Documentation
Devart.Data.SQLite Namespace / SQLiteConnection Class / Rollback Method
Example

On this page
    Rollback Method (SQLiteConnection)
    On this page
    Rolls back a transaction from a pending state.
    Syntax
    'Declaration
     
    Public Sub Rollback() 
    public void Rollback()
    Example
    The following example demonstrates how to use Commit and Rollback methods.
    public void RunSQLiteTransaction(string myConnString)
    {
      SQLiteConnection sqLiteConnection = new SQLiteConnection(myConnString);
      sqLiteConnection.Open();
    
      SQLiteCommand sqLiteCommand = new SQLiteCommand();
      sqLiteConnection.BeginTransaction();
      try
      {
        sqLiteCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')";
        sqLiteCommand.ExecuteNonQuery();
        sqLiteCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(60, 'PRODUCTION')";
        sqLiteCommand.ExecuteNonQuery();
        sqLiteConnection.Commit();
        Console.WriteLine("Both records are written to database.");
      }
      catch(Exception e)
      {
        sqLiteConnection.Rollback();
        Console.WriteLine(e.ToString());
        Console.WriteLine("Neither record was written to database.");
      }
      finally
      {
        sqLiteConnection.Close();
      }
    }
    Public Sub RunSQLiteTransaction(myConnString As String)
      Dim sqLiteConnection As New SQLiteConnection(myConnString)
      sqLiteConnection.Open()
    
      Dim sqLiteCommand As New SQLiteCommand()
      sqLiteConnection.BeginTransaction()
      Try
        sqLiteCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
        sqLiteCommand.ExecuteNonQuery()
        sqLiteCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(60, 'PRODUCTION')"
        sqLiteCommand.ExecuteNonQuery()
        sqLiteConnection.Commit()
        Console.WriteLine("Both records are written to database.")
      Catch e As Exception
        sqLiteConnection.Rollback()
        Console.WriteLine(e.ToString())
        Console.WriteLine("Neither record was written to database.")
      Finally
        sqLiteConnection.Close()
      End Try
    End Sub
    See Also