5.8. Adding Parent/Child Rows with Autoincrementing Keys

Problem

You want to insert related parent/child records into a DataSet where the primary key of the parent table is an automatically incrementing value.

Solution

Use the DataColumn object's AutoIncrementSeed and AutoIncrementStep properties.

The solution uses two tables, ParentAutoincrementKey and ChildAutoincrementKey, related on the ParentId column in each table. The tables are shown in Figures 5-13 and 5-14. The primary key in each table is an identity column with a seed of 1 and an increment...