Esempio del metodo Append di Keys, di Type di Key e delle proprietà RelatedColumn, RelatedTable e UpdateRule (VB)
Il codice seguente illustra come creare una nuova relazione di chiave esterna tra due tabelle esistenti denominate Customers e Orders.
' BeginCreateKeyVB
Sub Main()
On Error GoTo CreateKeyError
Dim kyForeign As New ADOX.Key
Dim cat As New ADOX.Catalog
' Connect to the catalog.
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
' Define the foreign key.
kyForeign.Name = "CustOrder"
kyForeign.Type = adKeyForeign
kyForeign.RelatedTable = "Customers"
kyForeign.Columns.Append "CustomerId"
kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
kyForeign.UpdateRule = adRICascade
' Append the foreign key to the keys collection.
cat.Tables("Orders").Keys.Append kyForeign
'Delete the key t demonstrate the Delete method.
cat.Tables("Orders").Keys.Delete kyForeign.Name
'Clean up.
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Set kyForeign = Nothing
Exit Sub
CreateKeyError:
Set cat = Nothing
Set kyForeign = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndCreateKeyVB
Vedere anche
Metodo Append (raccolta Columns ADOX)
Metodo Append (raccolta Keys ADOX)
Oggetto Catalog (ADOX)
Oggetto Column (ADOX)
Raccolta Columns (ADOX)
Oggetto Key (ADOX)
Raccolta Keys (ADOX)
Proprietà Name (ADOX)
Proprietà RelatedColumn (ADOX)
Proprietà RelatedTable (ADOX)
Oggetto Table (ADOX)
Raccolta Tables (ADOX)
Proprietà Type (Key) (ADOX)
Proprietà UpdateRule (ADOX)
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per