Getting MsAccess table names

只愿长相守 提交于 2019-12-24 11:43:38

问题


I am looking to get all the tables given a msAccess 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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/16864790/getting-msaccess-table-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!