asp.net.ph

DataColumn.AutoIncrement Property

System.Data Namespace   DataColumn Class


Returns or sets a value indicating whether the column automatically increments the value of the column for new rows added to the table.

Syntax


Script DataColumn.AutoIncrement [ = true | false ]

Property Value

This property accepts or returns only a boolean value: true if the value of the column increments automatically; otherwise, false. The default is false.

Exceptions


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

Remarks

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 ( that is, 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 DataRow class's ItemArray property 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 a null reference in the column's position in the array. For more details, see the DataRow class's ItemArray property.

Example

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

private void AddAutoIncrementColumn ( ) {
   DataColumn myColumn = new DataColumn ( );
   myColumn.DataType = System.Type.GetType ( "System.Int32" );

   myColumn.AutoIncrement = true;
   myColumn.AutoIncrementSeed = 1000;
   myColumn.AutoIncrementStep = 10;

   // add the column to a new DataTable.
   DataTable myTable = new DataTable ( "MyTable" );
   myTable.Columns.Add ( myColumn );
}
  C# VB

See Also

DataColumn Members   AutoIncrementSeed   AutoIncrementStep   Expression   ItemArray   NewRow 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