获取MsAccess表名称 [英] Getting MsAccess table names
本文介绍了获取MsAccess表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找给定msAccess文件的所有表.以下是我的工作:
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;
}
}
但是,尽管返回了所有表名,但似乎每个表名都返回了10次.为什么这样做?
However, although all the table names are returned, it seems each one is returned 10 times. Why is it doing that?
推荐答案
我认为您需要更改con.GetSchema调用以获取表而不是列-例如
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.
这篇关于获取MsAccess表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文