共用方式為


Catalog ActiveConnection 屬性範例 (VB)

ActiveConnection 屬性設定為有效的開放式連線會「開啟」目錄。 透過開啟的目錄,您可以存取包含在該目錄內的結構描述物件。

' BeginOpenConnectionVB  
Sub Main()  
    On Error GoTo OpenConnectionError  
  
    Dim cnn As New ADODB.Connection  
    Dim cat As New ADOX.Catalog  
  
    cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _  
        "Data Source= 'Northwind.mdb';"  
    Set cat.ActiveConnection = cnn  
    Debug.Print cat.Tables(0).Type  
  
    'Clean up  
    cnn.Close  
    Set cat = Nothing  
    Set cnn = Nothing  
    Exit Sub  
  
OpenConnectionError:  
  
    Set cat = Nothing  
  
    If Not cnn Is Nothing Then  
        If cnn.State = adStateOpen Then cnn.Close  
    End If  
    Set cnn = Nothing  
  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
' EndOpenConnectionVB  

ActiveConnection 屬性設定為有效的連線字串也會「開啟」目錄。

Attribute VB_Name = "Catalog"  

另請參閱

ActiveConnection 屬性 (ADOX)
Catalog 物件 (ADOX)
Table 物件 (ADOX)
Tables 集合 (ADOX)
Type 屬性 (Table) (ADOX)