程式碼如下: 90..04.01 修正部份程式碼 (將北風資料庫連接方式,由讀者手動改為尋找讀者的登錄檔替代)Private Sub Command1_Click() Dim intIndex As Integer Dim objCon As ADODB.Connection Dim objRst As ADODB.Recordset
' 產生一個新Connection物件,並設定objCon作為存取的物件變數。 Set objCon = New ADODB.Connection
' 使用Open方法連接,並設定相關參數。 objCon.Open gstrConn_NWind
' 找出資料表名稱。 Set objRst = objCon.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
' 列舉名稱、型態、修改日期資料。 If objRst.RecordCount <> 0 Then intIndex = 1 Do Until objRst.EOF lvw1.ListItems.Add intIndex, , objRst.Fields("TABLE_NAME") lvw1.ListItems(intIndex).SubItems(1) = objRst.Fields("TABLE_TYPE") lvw1.ListItems(intIndex).SubItems(2) = Format(objRst.Fields("DATE_MODIFIED"), "yyyy/mm/dd") intIndex = intIndex + 1 objRst.MoveNext Loop End If
objRst.Close objCon.Close Set objRst = Nothing Set objCon = Nothing End Sub 其中 adSchemaTables 相關屬性列表如下: --------------------------------------------------------------------------------
Column Name Type Description (相對於Access 2000) --------------------------------------------------------------------------------
ALIAS The table is an alias TABLE The table is a normal table SYNONYM The table is a synonym SYSTEM TABLE The table is a system tabLe VIEW The table is a view GLOBAL TEMPORARY The table is a global, temporary table LOCAL TEMPORARY The table is a local, temporary table --------------------------------------------------------------------------------
Dim intIndex As Integer
Dim objCon As ADODB.Connection
Dim objRst As ADODB.Recordset
' 產生一個新Connection物件,並設定objCon作為存取的物件變數。
Set objCon = New ADODB.Connection
' 使用Open方法連接,並設定相關參數。
objCon.Open gstrConn_NWind
' 找出資料表名稱。
Set objRst = objCon.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
' 列舉名稱、型態、修改日期資料。
If objRst.RecordCount <> 0 Then
intIndex = 1
Do Until objRst.EOF
lvw1.ListItems.Add intIndex, , objRst.Fields("TABLE_NAME")
lvw1.ListItems(intIndex).SubItems(1) = objRst.Fields("TABLE_TYPE")
lvw1.ListItems(intIndex).SubItems(2) = Format(objRst.Fields("DATE_MODIFIED"), "yyyy/mm/dd")
intIndex = intIndex + 1
objRst.MoveNext
Loop
End If
objRst.Close
objCon.Close
Set objRst = Nothing
Set objCon = Nothing
End Sub
其中 adSchemaTables 相關屬性列表如下:
--------------------------------------------------------------------------------
Column Name Type Description (相對於Access 2000) --------------------------------------------------------------------------------
TABLE_CATALOG String
TABLE_SCHEMA String
TABLE_NAME String 名稱
TABLE_TYPE String 類型
TABLE_GUID GUID
DESCRIPTION String 敘述
TABLE_PROPID Long
DATE_CREATED Date/Time 建立
DATE_MODIFIED Date/Time 修改 --------------------------------------------------------------------------------
TABLE_TYPE 只會顯示下列類型,或是其值 (provider-specific value):
--------------------------------------------------------------------------------
類型,或是其值 說明 --------------------------------------------------------------------------------
ALIAS The table is an alias
TABLE The table is a normal table
SYNONYM The table is a synonym
SYSTEM TABLE The table is a system tabLe
VIEW The table is a view
GLOBAL TEMPORARY The table is a global, temporary table
LOCAL TEMPORARY The table is a local, temporary table --------------------------------------------------------------------------------