如何在MS Access中使用C#获取所有表名和列名? [英] How to get all table names and also column name using C# in MS Access?
本文介绍了如何在MS Access中使用C#获取所有表名和列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#在Access 2007中获取所有表的名称和列表的名称?
How to get the name of all the tables and the name of the column table in Access 2007 with C#?
我想将表名绑定到组合框,将列名绑定到列表框.
I want to bind the name of the table to a combobox and the column name to a listbox.
推荐答案
此简单方法将为您提供一个包含所有列名称的数据表
This simple method will give you back a datatable that contains the name of all your columns
void Main()
{
using(OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=D:\temp\temp.mdb;Persist Security Info=False;"))
{
con.Open();
DataTable schema = con.GetSchema("Columns");
foreach(DataRow row in schema.Rows)
Console.WriteLine("TABLE:" + row.Field<string>("TABLE_NAME") +
" COLUMN:" + row.Field<string>("COLUMN_NAME"));
}
}
您还可以尝试将列"更改为表",以获得具有更多表信息的其他数据表. (索引也称为索引")
You could also try to change "Columns" with "Tables" to obtain a different datatable with more info on your tables. (Also "Indexes" for indexes)
这篇关于如何在MS Access中使用C#获取所有表名和列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文