Setting Up Autoincremented Fields
When a new row is added to a DataTable, the empty row is created by calling DataTable.NewRow. The DataTable knows the schema for the row that it must create and instantiates the new row to match the schema. That means the new row holds the right DataColumns with the correct data types ready for you to set the data.
The DataColumn.AutoIncrement property can be set to tell the DataTable to set the value for a DataColumn automatically when a new row is created. This is an especially useful feature for DataColumns that represent the primary key of a table, since the key can be automatically created for you.
There are three important properties in the DataColumn that relate to autoincremented fields:
DataColumn.AutoIncrement ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access