O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required