asp.net.ph

DataColumn.Unique Property

System.Data Namespace   DataColumn Class


Sets or retrieves a value indicating whether the values in each row of the column must be unique.

Syntax


Script DataColumn.Unique = [ true | false ]

Property Value

This property accepts or returns only a boolean value: true if the value must be unique; otherwise, false. The default is false.

Exceptions


Exception Type Condition
ArgumentException Occurs when the column is a calculated column.

Remarks

Once this property is set, a unique constraint will be created on this column to ensure values are unique.

Alternatively, you can also add a UniqueConstraint to the DataTable to which this column belongs to ensure the values are unique.

Example

The following example initializes new DataColumn, sets its properties, and adds it to a table's columns collection.

private void AddColumn ( DataTable myTable ) {
   // add a DataColumn to the collection and set its properties.
   DataColumn myColumn;
   // the constructor sets the ColumnName of the column.
   myColumn = new DataColumn ( "Total" );
   myColumn.DataType = System.Type.GetType ( "System.Decimal" );
   myColumn.ReadOnly = true;
   myColumn.Expression = "UnitPrice * Quantity";
   myColumn.Unique = false;
}
  C# VB

See Also

DataColumn Members   AllowDBNull   UniqueConstraint   Constraints Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph