您的位置:首页 > 其它

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

2008-05-30 21:23 405 查看
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"]};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐