DataColumn.Unique 属性

获取或设置一个值,该值指示列的每一行中的值是否必须是唯一的。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public Property Unique As Boolean
用法
Dim instance As DataColumn
Dim value As Boolean

value = instance.Unique

instance.Unique = value
public bool Unique { get; set; }
public:
property bool Unique {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Unique ()

/** @property */
public void set_Unique (boolean value)
public function get Unique () : boolean

public function set Unique (value : boolean)

属性值

如果值必须是唯一的,则为 true;否则为 false。默认为 false

异常

异常类型 条件

ArgumentException

列是计算出的列。

备注

一旦此属性从“false”更改为“true”,就将为此列创建唯一约束,以确保值是唯一的。

示例

下面的示例创建新的 DataColumn,设置它的属性,并将其添加到表的列集合中。

Private Sub AddColumn(table As DataTable)
    ' Add a DataColumn to the collection and set its properties.
    ' The constructor sets the ColumnName of the column.
    Dim column As DataColumn = New DataColumn("Total")
    column.DataType = System.Type.GetType("System.Decimal")
    column.ReadOnly = True
    column.Expression = "UnitPrice * Quantity"
    column.Unique = False
End Sub
private void AddColumn(DataTable table)
{
    // Add a DataColumn to the collection and set its properties.
    // The constructor sets the ColumnName of the column.
    DataColumn column = new DataColumn("Total");
    column.DataType = System.Type.GetType("System.Decimal");
    column.ReadOnly = true;
    column.Expression = "UnitPrice * Quantity";
    column.Unique = false;
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataColumn 类
DataColumn 成员
System.Data 命名空间
DataColumn.AllowDBNull 属性
UniqueConstraint
Constraints