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

On this page
    Commit Method (SQLiteConnection)
    On this page
    Commits the database transaction.
    Syntax
    'Declaration
     
    Public Sub Commit() 
    public void Commit()
    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();
      sqLiteCommand.Connection = sqLiteConnection;
      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()
      sqLiteCommand.Connection = sqLiteConnection
      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