Primary Keys are set on the DataTable of the data. Simply get the column and set the .Unique property as true;
//This sets a single column
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Id");
dc.Unique = true;
dt.Columns.Add(dc);
//This sets several columns
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("Id1");
DataColumn dc2 = new DataColumn("Id2");
dt.Columns.Add( dc1);
dt.Columns.Add( dc2);
dt.PrimaryKey = new DataColumn[] {dc1, dc2};
Regards,
Dom
|