Reputation: 4749
I am looking to get all the tables given an MS-Access file. The following is what I do:
public override List<string> GetTables()
{
using (OleDbConnection con = new OleDbConnection(Path))
{
con.Open();
DataTable schema = con.GetSchema("Columns");
List<string> tables= new List<string>();
foreach (DataRow row in schema.Rows)
{
tables.Add(row.Field<string>("TABLE_NAME"));
}
return tables;
}
}
However, although all the table names are returned, it seems each one is returned 10 times. Why is it doing that?
Upvotes: 1
Views: 4959
Reputation: 98
You can also show hidden and system tables to view the table that stores the names of all the other tables in your database. You can query this table either using a query object or in vba using a db recordset.
https://www.techonthenet.com/access/database/view_systables2007.php
Upvotes: 0
Reputation: 4266
I think you need to change your con.GetSchema call to get Tables not Columns - e.g.
DataTable schema = con.GetSchema("Tables");
It looks like you are getting a list of all the columns in the database and then only using the table name fields in the results, so it will appear multiple times.
Upvotes: 5