using System.Data.OleDb; string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\sample.accdb"; OleDbConnection connection = new OleDbConnection(connectionString); connection.Open(); OleDbTransaction transaction = connection.BeginTransaction(); // Perform database operations here transaction.Commit(); connection.Close();
using System.Data.OleDb; string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\sample.accdb"; OleDbConnection connection = new OleDbConnection(connectionString); try { connection.Open(); OleDbTransaction transaction = connection.BeginTransaction(); // Perform database operations here transaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { connection.Close(); }In this example, we again create a new OleDbConnection object and open a connection to a sample Access database. We then use a try-catch-finally block to handle any exceptions that may occur during the database operations. We also use the BeginTransaction method to start a new transaction and commit it using the Commit method. Finally, we close the connection in the finally block. Package library: System.Data.OleDb