If I can open a connection to an MS Access file in C#, how can I retrieve a list of the different tables that exist in the Access DB (and if possible, any meta-data associated with the tables)?
Add the table called [MSysObjects] and select the fields called [Name] and [Type]. The criteria of [Type] = 5 will get your query names, and a criteria of [Type] = 1 with a [Flags] = 0 will get your table names.
On the Home tab, in the Find group, click Find. The Find and Replace dialog box appears, with the Find tab selected. In the Find What box, type the value for which you want to search. To change the field that you want to search or to search the entire underlying table, click the appropriate option in the Look In list.
I just found the following solution from David Hayden
// Microsoft Access provider factory
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DataTable userTables = null;
using (DbConnection connection = factory.CreateConnection()) {
// c:\test\test.mdb
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\test\\test.mdb";
// We only want user tables, not system tables
string[] restrictions = new string[4];
restrictions[3] = "Table";
connection.Open();
// Get list of user tables
userTables = connection.GetSchema("Tables", restrictions);
}
List<string> tableNames = new List<string>();
for (int i=0; i < userTables.Rows.Count; i++)
tableNames.Add(userTables.Rows[i][2].ToString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With