Append (méthode) sur la collection Keys, Type de clé ; RelatedColumn, RelatedTable et UpdateRule, exemple de propriétés (VB)
Le code suivant montre comment créer une relation de clé étrangère entre deux tables existantes nommées Clients et Commandes.
' 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
Voir aussi
Append, méthode (colonnes ADOX)
Append, méthode (clés ADOX)
Catalog, objet (ADOX)
Column, objet (ADOX)
Columns, collection (ADOX)
Key, objet (ADOX)
Keys, collection (ADOX)
Name, propriété (ADOX)
RelatedColumn, propriété (ADOX)
RelatedTable, propriété (ADOX)
Table, objet (ADOX)
Tables, collection (ADOX)
Type, propriété (clé) (ADOX)
UpdateRule, propriété (ADOX)
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour