DataTable::PrimaryKey Property

 

Gets or sets an array of columns that function as primary keys for the data table.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

public:
property array<DataColumn^>^ PrimaryKey {
	array<DataColumn^>^ get();
	void set(array<DataColumn^>^ value);
}

Property Value

Type: array<System.Data::DataColumn^>^

An array of DataColumn objects.

Exception Condition
DataException

The key is a foreign key.

The primary key of a table must be unique to identify the record in the table. It's also possible to have a table with a primary key made up of two or more columns. This occurs when a single column can't contain enough unique values. For example, a two column primary key might consist of a "FirstName" and "LastName" column. Because primary keys can be made up of more than one column, the PrimaryKey property consists of an array of DataColumn objects.

The first example shows how to return the primary key columns for a DataTable displayed in a DataGrid. The second example demonstrates how to set the primary key columns for a DataTable.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: