Views Append 方法範例 (VB)

下列程式碼示範如何使用 Command 物件和 Views collection Append 方法,在基礎資料來源中建立新的視圖。

' BeginCreateViewVB  
Sub Main()  
    On Error GoTo CreateViewError  
    Dim cmd As New ADODB.Command  
    Dim cat As New ADOX.Catalog  
    ' Open the Catalog  
    cat.ActiveConnection = _  
        "Provider='Microsoft.Jet.OLEDB.4.0';" & _  
        "Data Source='Northwind.mdb';"  
    ' Create the command representing the view.  
    cmd.CommandText = "Select * From Customers"  
    ' Create the new View  
    cat.Views.Append "AllCustomers", cmd  
    'Clean up  
    Set cat.ActiveConnection = Nothing  
    Set cat = Nothing  
    Set cmd = Nothing  
    Exit Sub  
    Set cat = Nothing  
    Set cmd = Nothing  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
' EndCreateViewVB  


ActiveConnection 屬性 (ADOX)
附加方法 (ADOX Views)
(ADOX) 的目錄物件
View Object (ADOX)
Views 集合 (ADOX)