System.Data.DataColumn.AutoIncrement Property

Gets or sets a value that indicates whether the column automatically increments the value of the column for new rows added to the table.

Syntax

[System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)]
[System.ComponentModel.DefaultValue(false)]
public bool AutoIncrement { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

If the type of this column is not Int16, Int32, or Int64 when this property is set, the DataColumn.DataType property is coerced to Int32. An exception is generated if this is a computed column. The DataColumn.Expression property is set. The incremented value is used only if the row's value for this column, when added to the columns collection, is equal to the default value.

You can create a new row using the DataRow.ItemArray property of the System.Data.DataRow class and passing in an array of values. This is a potential problem for a column with its DataColumn.AutoIncrement set to true, because its value is generated automatically. To use the DataRow.ItemArray property, place null in the column's position in the array. For more information, see the DataRow.ItemArray property of the System.Data.DataRow class.

If the type of the column is System.Data.SqlTypes.SqlInt16 or System.Data.SqlTypes.SqlInt32, DataColumn.AutoIncrement will not work. Use Int16 or Int32 instead.

If the type of the column is System.Data.SqlTypes.SqlInt64 or System.Data.SqlTypes.SqlDecimal, DataColumn.AutoIncrement will only partially work. Use Int64 or Decimal instead.

When the DataColumn.AutoIncrementStep value is added to the current value, the overflow check is suppressed.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0