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

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To set a data column to contain auto-generated numbers

  1. Open your dataset in the Dataset Designer.

  2. Select the column you want to populate with auto-generated numbers.

  3. In the Properties window, set the following properties:

    Property

    Setting

    AutoIncrement

    true

    AutoIncrementSeed

    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.

    AutoIncrementStep

    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 Form in a Windows Application

How to: Create DataTables

How to: Add Columns to a DataTable

Concepts

What's New in Data

TableAdapter Overview

Data Sources Overview

Reference

Data Sources Window

DataTable

Other Resources

Data Walkthroughs

Validating Data