[ Team LiB ] Recipe Using Auto-Incrementing Columns Without Causing Conflicts Problem You want to use an AutoIncrement column in a table without producing values that may be duplicated in records added by other users. Solution Use the AutoIncrementSeed and AutoIncrementStep properties of the AutoIncrement column. | Team LiB Recipe Using Auto-Incrementing Columns Without Causing Conflicts Problem You want to use an AutoIncrement column in a table without producing values that may be duplicated in records added by other users. Solution Use the AutoIncrementSeed and AutoIncrementStep properties of the AutoIncrement column. The sample code contains two event handlers Sets up the sample by creating a DataTable and programmatically defining the schema to match the Categories table in Northwind. The AutoIncrementSeed and AutoIncrementStep property values are both set to -1 for the AutoIncrement primary key column the CategoryID. A DataAdapter is created and used to fill the DataTable. The default view of the table is bound to the data grid on the form. Add Creates a new row in the Categories DataTable using the entered CategoryName and Description values and the automatically generated CategoryID field. The C code is shown in Example 4-1. Example 4-1. File Namespaces variables and constants using System using using using Table name constants private const String CATEGORIES_TABLE Categories Field name constants private const String CATEGORYID_FIELD CategoryID private const String CATEGORYNAME_FIELD CategoryName private const String DESCRIPTION_FIELD Description private DataTable dt . . . private void AutoIncrementWithoutConflictForm_Load object sender e Create the Categories table. dt new DataTable CATEGORIES_TABLE Add the identity column. DataColumn col CATEGORYID_FIELD typeof false true -1 -1 Set the primary key. new DataColumn col Add the other columns. col CATEGORYNAME_FIELD typeof false 15 DESCRIPTION_FIELD typeof Fill the table. .