string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Data\\mydatabase.accdb;"; string query = "SELECT ID, Name, Age FROM People"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(query, connection); connection.Open(); using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); int age = reader.GetInt32(2); Console.WriteLine($"ID: {id}, Name: {name}, Age: {age}"); } } }
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Data\\mydatabase.accdb;"; string query = "INSERT INTO People (Name, Age) VALUES ('John', 33)"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(query, connection); connection.Open(); int rowsAffected = command.ExecuteNonQuery(); Console.WriteLine($"Rows affected: {rowsAffected}"); }In this example, we are inserting a new record into the People table, with a Name of 'John' and an Age of 33. We are using the ExecuteNonQuery method of the OleDbCommand class to execute the query and return the number of rows affected. Package library: System.Data.OleDb