用vb.net,使用ADO.NET,怎么得到Access数据库中所有表的名称
用vb.net,使用ADO.NET,如何得到Access数据库中所有表的名称
用vb.net,使用ADO.NET,如何得到Access数据库中所有表的名称?如何判断一个表在Access数据库中是否存在?
------解决方案--------------------
举个例子:C#的,你可以改成VB.NET
OleDbConnection cn = new OleDbConnection();
DataTable schemaTable;
//Connect to the Northwind database in SQL Server.
//Be sure to use an account that has permission to list tables.
cn.ConnectionString = "Provider=SQLOLEDB;Data Source=server;User ID=sa;
Password=password;Initial Catalog=Northwind ";
cn.Open();
//Retrieve schema information about tables.
//Because tables include tables, views, and other objects,
//restrict to just TABLE in the Object array of restrictions.
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new Object[] {null, null, null, "TABLE "});
//List the table name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++) {
Console.WriteLine(schemaTable.Rows[i].ItemArray[2].ToString());
}
//Explicitly close - don 't wait on garbage collection.
cn.Close();
//Pause
Console.ReadLine();
------------------------------
上面的作用就是获得表名,表名在ItemArray数组里面存.
你可以遍历ItemArray数组,判断你想要判断的表是否存在.
用vb.net,使用ADO.NET,如何得到Access数据库中所有表的名称?如何判断一个表在Access数据库中是否存在?
------解决方案--------------------
举个例子:C#的,你可以改成VB.NET
OleDbConnection cn = new OleDbConnection();
DataTable schemaTable;
//Connect to the Northwind database in SQL Server.
//Be sure to use an account that has permission to list tables.
cn.ConnectionString = "Provider=SQLOLEDB;Data Source=server;User ID=sa;
Password=password;Initial Catalog=Northwind ";
cn.Open();
//Retrieve schema information about tables.
//Because tables include tables, views, and other objects,
//restrict to just TABLE in the Object array of restrictions.
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new Object[] {null, null, null, "TABLE "});
//List the table name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++) {
Console.WriteLine(schemaTable.Rows[i].ItemArray[2].ToString());
}
//Explicitly close - don 't wait on garbage collection.
cn.Close();
//Pause
Console.ReadLine();
------------------------------
上面的作用就是获得表名,表名在ItemArray数组里面存.
你可以遍历ItemArray数组,判断你想要判断的表是否存在.