How to: Create an Autonumber DataColumn
Data columns (DataColumn) often contain auto-generated sequential numbers; for example, primary keys and ID columns. You can load auto-generated numbers in data columns by setting the AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties of the data column.
When data columns are created by means of Visual Studio design tools, the columns are automatically marked as AutoIncrement. When you update a table in the database that contains an Identity column, the values created with the auto-numbering feature are not sent to the database.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
To set a data column to contain auto-generated numbers
Open your dataset in the Dataset Designer.
Select the column you want to populate with auto-generated numbers.
In the Properties window, set the following properties:
Property
Setting
true
If you want to begin at a number different from the default value of 0, set this value to the starting number for this column.
In each new row, the column value is incremented by this value.
Note
Setting a data column to auto-increment does not automatically designate the column as a primary key. To set a data column as a primary key column, see How to: Set a Data Column as the Primary Key.
See Also
Tasks
Walkthrough: Displaying Data on a Windows Form
How to: Add Columns to a DataTable
Reference
Concepts
What's New in Data Application Development