string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\MyDatabase.accdb;"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); DataTable tableSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); foreach (DataRow row in tableSchema.Rows) { Console.WriteLine(row["TABLE_NAME"].ToString()); } }
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\MyDatabase.accdb;"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); string[] restrictions = new string[4]; restrictions[2] = "MyTable"; DataTable tableSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, restrictions); foreach (DataRow row in tableSchema.Rows) { Console.WriteLine(row["COLUMN_NAME"].ToString() + " (" + row["DATA_TYPE"].ToString() + ")"); } }This example connects to a Microsoft Access database, retrieves the schema of a specific table called "MyTable", and prints the names and data types of its columns to the console. Package Library: This code belongs to System.Data.OleDb namespace which is part of the .NET Framework Class Library.