用C#连接ACCESS数据库后,怎样能查到数据库有几个表,并将所有表名显示在listbox里,急求回复!!!

来源:百度知道 编辑:UC知道 时间:2024/05/25 14:52:31

select Name from MSysObjects where [type]=1 and Name not like 'MSys%'"

MSysObjects 表 属性先改为可读可写 ,他是隐藏的

//using System.Data;
//using System.Data.OleDb;

this.listbox.Items.Clear();
try {
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;User ID=admin;Data Source=your.mdb");
conn.Open();

DataTable table = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});
foreach(DataRow drow in table.Rows) {
this.listbox.Items.Add(drow[2].ToString(), true);
}
conn.Close();
} catch {}

你使用SELECT * from MSysObjects;但需要过滤系统表和查询。