Key object

The Key object allows you to define the keys for a table. The Keys collection contains all of the keys for a table.

Creating a new key

Use the Append method to create a new key. The Append method automatically adds the key to the Keys collection.

{Append a new key, named "PrimaryKey", to the Keys collection.}
tableKey = adoxTable.Keys.Append("PrimaryKey");

Retrieving an existing key

You can retrieve an existing key from the Keys collections with the Item property by the number associated with the key.

{Retrieve the first key.}
tableKey = adoxTable.Keys.Item[0];

You can also access keys by the name of the key.

{Retrieve the key named "PrimaryKey".}
tableKey = adoxTable.Keys.Item["PrimaryKey"];

Retrieving and setting the name of a key

Use the Name property to retrieve the name of a key.

{Retrieve the name of a key.}
name = tableKey.Name;

You can also use the Name property to set the name of a key.

{Set the name of a key.}
tableKey.Name = "PrimaryKey";

Retrieving and setting the type of a key

Use the Type property to retrieve the type of a key. The returned value is equivalent to a constant contained in the KeyTypeEnum enumeration.

{Retrieve the type of a key.}
keyType = tableKey.Type;

You can also use the Type property to set the type of a key.

{Set the type of the key as primary.}
tableKey.Type = ADOX.adKeyPrimary;


Documentation Feedback