如何在程序里获取Access数据库中的所有表和查询的列表

cloonist 2005-07-16 03:26:12
就像SQLServer中可以使用SQL语句:sp_help 获得一个数据库的所有表和视图的列表一样,如何在Access数据库中也能获得其所有表和查询的列表呢?
...全文
203 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2006-02-21
  • 打赏
  • 举报
回复
The following statement returns all the views in an Access database.

DataTable dt =
this.oleDbConnection1.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new
object[] {null, null, null, "VIEW"});

For an example, visit http://www.aspitalia.com/articoli/db/storedqueries.aspx?page=3

An Access Stored procedure directly translates into an Access Query. That’s how it’s stored on the database. See

http://www.devcity.net/Articles/18/msaccess_sp.aspx

Note:queries created programmatically are invisible in Access. You can view the stored procedures by using Tools->Analyze->Documenter the select Queries Tab, select your query and click OK.
whwang 2006-02-08
  • 打赏
  • 举报
回复
Public Sub ListTablesAndQuerys()

Dim Tb As TableDef
Dim ncStr As String
Dim DB As Database

Set DB = CurrentDb

For Each Tb In DB.TableDefs
If Len(Tb.Connect) > 0 Then '判断是否链接表
Debug.Print "链结表:" & Tb.name
Else
Debug.Print "本地表:" & Tb.name
End If
Next

Dim qry As QueryDef
For Each qry In DB.QueryDefs
If qry.Connect <> "" Then
Debug.Print "传递查询:" & qry.name
Else
Debug.Print "本地查询:" & qry.name
End If
Next

End Sub
athossmth 2005-08-01
  • 打赏
  • 举报
回复
要使用DAO或者ADOX
wwonion 2005-07-22
  • 打赏
  • 举报
回复
从Access数据库中取出所有表名,不包括系统表
using System;
using System.Data;
using System.Data.OleDb;


string ConnectionString = @"Provider=Microsoft.Jet.OleDB.4.0;Data Source=C:\Program Files\Microsoft Office\Office\1033\FPNWIND.mdb";
OleDbConnection conn = new OleDbConnection(ConnectionString);
conn.Open();

DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});
foreach (DataRow dr in schemaTable.Rows)
{
//表名
Console.WriteLine(dr["TABLE_NAME"]);

//字段名
DataTable columnTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new object[] {null, null, dr["TABLE_NAME"].ToString(),null});


foreach(DataRow dr2 in columnTable.Rows)
{
Console.WriteLine(" {0}", dr2["COLUMN_NAME"]);
}

}
conn.Close();

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧