Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i want to get a list of all tables and their columns from a specific Access database
i tried
SELECT * FROM MSysObjects

but nothing retrieved
Posted
Updated 21-Aug-15 23:42pm
v2

1 solution

You can get the list of tables by using MS Access Provider factory. Got the solution from web.
C#
// 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());
</string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900