方法一:直接用ado的OpenSchema()方法打開adSchemaTables,建立一個schema記錄集
Code:
<%
Const adSchemaTables = 20
adSchemaColumns = 4
dim Conn,db
dim ConnStr
db="temp.mdb" 'ACCESS數據庫的文件名,請使用相對於網站根目錄的的絕對路徑
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
Dim rstSchema
Dim I
Set rstSchema = Conn.OpenSchema(adSchemaTables)
Do while not rstSchema.EOF
response.write("Table name: "& rstSchema("TABLE_NAME") & vbCr & _
"Table type: " & rstSchema("TABLE_TYPE") & vbCr)
response.write("<br/>")
I = I + 1
rstSchema.MoveNext
Loop
rstSchema.Close
conn.Close
%>
方法二:Access 系統表 MsysObjects 包含了數據庫對象列表。盡管未在文檔中記載,你仍可通過查詢它來獲取你想要的。但是默認情況下無法操作系統表,必須手動設定權限收才能查詢系統表。
請參考以下動畫:如何獲取對msysobject的操作權限 http://blog.iyi.cn/user/david/archives/IMAGES/msobject.swf
但是我在access2003中找不到這幾個系統表,不知道是不是m$增強了access的安全性。
使用下列 SQL 語句來獲取你想要的
Code:
查詢:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)=5 ORDER BY MSysObjects.Name;
窗體:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)=-32768 ORDER BY MSysObjects.Name;
表:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (Left$([Name],4) <> "Msys") AND (MSysObjects.Type)=1 ORDER BY MSysObjects.Name;
報表:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32764 ORDER BY MSysObjects.Name;
模塊:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32761 ORDER BY MSysObjects.Name;
宏:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32766 ORDER BY MSysObjects.Name;