如何获得ACCESS数据库的中所有的表
我要作一个工具需要获得数据库中的所有表,请问该如何实现? 不知道其中的表和其结构.
[解决办法]
saucer(思归)回复于 2004-11-02 22:28:03 得分 0 you can use a query like
SELECT MSysObjects.Name
FROM MSysObjects
WHERE ((Left([name],4) <> "MSys ") AND ((MSysObjects.Type)=1))
ORDER BY MSysObjects.Name;
or use OleDbConnection 's GetOleDbSchemaTable method, see
How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual C# .NET
http://support.microsoft.com/kb/309681/EN-US/
[解决办法]
回复人: RLearnP(深蓝) ( ) 信誉:100 2003-12-11 16:22:25Z 得分:16
?
我正在写 C#+Access 的程序,写了个函数,希望能帮到你。
/// <summary>
/// 取 Access 应用表的集合
/// </summary>
/// <param name= "sPath "> Access文件路径 </param>
/// <returns> </returns>
public string[] GetAccessTableName(string sPath)
{
OleDbConnection oleConn = new OleDbConnection();
oleConn.ConnectionString = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+sPath+ "; ";
DataTable dt = new DataTable();
try
{
oleConn.Open();
dt = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE "});
}
catch(Exception ee)
{
System.Windows.Forms.MessageBox.Show(ee.Message);
}
finally
{
oleConn.Close();
}
int iCount = dt.Rows.Count;
string[] rs = new string[iCount];
for(int i=0;i <iCount;i++)
{
rs[i] = dt.Rows[i][ "Table_name "].ToString();
}
return rs;
}