Access 系統表 MsysObjects 包含了數據庫對象列表, 盡管未在文檔中記載, 你仍可通過查詢它來獲取你想要的.
注: 請不要有意或無意地修改任何Access系統表,否則會出現不可意料的情況.
使用下列 SQL 語句來獲取你想要的
查詢:
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;
獲取Access的表裡的字段可用SQL語句 select * from Tabwhere 1=1
然後再用
DataTabel.Columns[index].ColumnName 獲取字段名
DataTabel.Columns[index].DataType.Name 可獲取字段類型