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 ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.