当为一列的时候
table.PrimaryKey=new DataColumn[]{table.Columns["CustID"]};
或者DataColum[] columns=new
DataColumn[1];
columns[0]=table.columns["CustID"];
table.PrimaryKey=columns;
当为多列的时候
table.PrimaryKey
=new DataColumn[]{table.Columns["CustId=D"],
table.Columns["CustName"]};
或者
DataColumn[] keyColumn = new
DataColumn[2];
keyColumn[0] = table.Columns["CustLName"];
keyColumn[1] =
table.Columns["CustFName"];
table.PrimaryKey = keyColumn;
C# DataColumn如何定义主键,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/xgzhen105/p/3756497.html