Code:
string dbLocation = "DatabaseName.mdb";
string tableName = "TableName";
string connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbLocation}";
DataTable results = new DataTable();
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand($"SELECT * FROM {tableName}", conn);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(results);
}
Conditions:
In order to the Office-Version that is installed (32/64 bit) you have to install Microsoft Access Database Engine 2010/2016 Redistributable (for me it was 2010).
Most office installations are 32 bit.
If you choose the right version an still get an error trying to install in silent mode
accessdatabaseengine.exe /quiet
- Add package
System.Data.OleDb
- Target plattform of the application has to be set to x86/x64 according to the other packages that are used
Still not solved:
- Actually you need to have Microsoft Access Database Engine Redistributable installed. If there exist any other methode without this, please let me know.