Export (0) Print
Expand All

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.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

public:
property bool AutoIncrement {
	bool get ();
	void set (bool value);
}

Property Value

Type: System::Boolean
true if the value of the column increments automatically; otherwise, false. The default is false.

ExceptionCondition
ArgumentException

The column is a computed column.

If the type of this column is not Int16, Int32, or Int64 when this property is set, the DataType property is coerced to Int32. An exception is generated if this is a computed column. The 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 ItemArray property of the DataRow class and passing in an array of values. This is a potential problem for a column with its AutoIncrement set to true, because its value is generated automatically. To use the ItemArray property, place nullptr in the column's position in the array. For more information, see the ItemArray property of the DataRow class.

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

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

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

The following example sets the AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft