Defining a Primary Key for a Table(该内存表DataTable 设置主键)

A database table commonly has a column, or group of columns, that uniquely identifies each row in the table. This identifying column or group of columns is called the primary key.
一个数据表都有一个或者是若干个列,而每个表都可以有唯一标识列的字段,这些能够标识字段的列就是所谓的主键。

When you identify a single DataColumn as the PrimaryKey for a DataTable, the table automatically sets the AllowDBNull property of the column to false and the Unique property to true. For multiple-column primary keys, only the AllowDBNull property is automatically set to false.
当你为确定一个列为数据表的主键的时候,表会自动为该列设置非空的属性。如果主键的内容涵盖多个列,那么这些列也都为非空。

The PrimaryKey property of a DataTable receives as its value an array of one or more DataColumn objects, as shown in the following examples. The first example defines a single column as the primary key.

例子:
workTable.PrimaryKey = new DataColumn[] {workTable.Columns["CustLName"], workTable.Columns["CustFName"]};
原文地址:https://www.cnblogs.com/shineqiujuan/p/1210949.html