资 源 简 介
C# 获取Access数据库的数据表名称,private void button1_Click(object sender, EventArgs e)
{//获取Access数据库的数据表名称
string MyAccessDBFile = @"F:Northwind.mdb";
string MyConnectString ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +MyAccessDBFile;
var MyConnection = new System.Data.OleDb.OleDbConnection(MyConnectString);
MyConnection.Open();
var MyTables = MyConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string MyInfo = MyAccessDBFile + "数据库的数据表包括:";
foreach (DataRow MyRow in MyTables.Rows)
{
string MyTable = MyRow["TABLE_NAME"].ToString();
MyInfo += MyTable + "、";
}
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);
}