Gets or sets a value that indicates whether the column automatically increments the value of the column for new rows added to the table.
Assembly: System.Data (in System.Data.dll)
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 set to true, because its value is generated automatically. To use the ItemArray property, place Nothing in the column's position in the array. For more information, see the ItemArray property of the DataRow class.
When the AutoIncrementStep value is added to the current value, the overflow check is suppressed.
Private Sub AddAutoIncrementColumn() Dim column As DataColumn = New DataColumn column.DataType = System.Type.GetType("System.Int32") With column .AutoIncrement = True .AutoIncrementSeed = 1000 .AutoIncrementStep = 10 End With ' Add the column to a new DataTable. Dim table As DataTable table = New DataTable table.Columns.Add(column) End Sub
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.