Export (0) Print
Expand All

Constraint.ConstraintName Property

The name of a constraint in the ConstraintCollection.

[Visual Basic]
Public Overridable Property ConstraintName As String
[C#]
public virtual string ConstraintName {get; set;}
[C++]
public: __property virtual String* get_ConstraintName();
public: __property virtual void set_ConstraintName(String*);
[JScript]
public function get ConstraintName() : String;
public function set ConstraintName(String);

Property Value

The name of the Constraint.

Exceptions

Exception Type Condition
ArgumentException The Constraint name is a null value or empty string.
DuplicateNameException The ConstraintCollection already contains a Constraint with the same name (The comparison is not case-sensitive.).

Remarks

The ConstraintCollection is returned by the Constraints property of the DataTable class.

Example

[Visual Basic, C#, C++] The following example iterates through the ConstraintCollection of a DataTable and prints each ConstraintName.

[Visual Basic] 
Private Sub PrintConstraintNames(myTable As DataTable)
    Dim cs As Constraint
    For Each cs In  myTable.Constraints
        Console.WriteLine(cs.ConstraintName)
    Next cs
End Sub

[C#] 
private void PrintConstraintNames(DataTable myTable){
   foreach(Constraint cs in myTable.Constraints){
      Console.WriteLine(cs.ConstraintName);
   }
}

[C++] 
private:
 void PrintConstraintNames(DataTable* myTable){
    System::Collections::IEnumerator* myEnum = myTable->Constraints->GetEnumerator();
    while (myEnum->MoveNext())
    {
       Constraint* cs = __try_cast<Constraint*>(myEnum->Current);
       Console::WriteLine(cs->ConstraintName);
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ 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

Constraint Class | Constraint Members | System.Data Namespace

Show:
© 2014 Microsoft