using System.Data.OleDb; string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Data/Database.accdb"; // Create a connection object OleDbConnection connection = new OleDbConnection(connectionString); // Open the connection connection.Open(); // Create a command object to select data from the table OleDbCommand command = new OleDbCommand("SELECT * FROM Customers", connection); // Execute the query and get a data reader OleDbDataReader reader = command.ExecuteReader(); // Loop through the results and write them to the console while (reader.Read()) { Console.WriteLine(reader["Name"] + " " + reader["Email"]); } // Close the reader and connection reader.Close(); connection.Close();
using System.Data.OleDb; string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Data/Workbook.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;\""; // Create a connection object OleDbConnection connection = new OleDbConnection(connectionString); // Open the connection connection.Open(); // Create a command object to update data in a sheet OleDbCommand command = new OleDbCommand("UPDATE [Sheet1$] SET Quantity = 10 WHERE PartNumber = 'A001'", connection); // Execute the query and get the number of rows affected int rowsAffected = command.ExecuteNonQuery(); Console.WriteLine(rowsAffected + " rows updated."); // Close the connection connection.Close();Package library: System.Data.OleDb is part of the .NET Framework Class Library, which is included with the .NET Framework installation.