Export (0) Print
Expand All

UniqueConstraint.IsPrimaryKey Property

Gets a value indicating whether or not the constraint is on a primary key.

[Visual Basic]
Public ReadOnly Property IsPrimaryKey As Boolean
[C#]
public bool IsPrimaryKey {get;}
[C++]
public: __property bool get_IsPrimaryKey();
[JScript]
public function get IsPrimaryKey() : Boolean;

Property Value

true, if the constraint is on a primary key; otherwise, false.

Remarks

A table usually includes a primary key that ensures every row is unique. In some tables, the primary key may be made up of more than one column. For example, a primary key for a table containing names might be made up of both the first and last names as well. To create a primary key with more than one column, set the Columns property to an array of DataColumn objects.

Example

[Visual Basic] The following example checks the IsPrimaryKey property.

[Visual Basic] 
Private Sub GetPrimaryKey()
    Dim rel As DataRelation
    Dim cstrt As UniqueConstraint
    ' Get a DataRelation from a DataSet.
    rel = DataSet1.Relations("CustomerOrders")
    ' Get the ParentKeyConstraint.
    cstrt = rel.ParentKeyConstraint
    ' Test if the IsPrimaryKey is true.
    If cstrt.IsPrimaryKey Then
       ' Do something
    End If
 End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

UniqueConstraint Class | UniqueConstraint Members | System.Data Namespace

Show:
© 2014 Microsoft