I have a small dataset with a few datatables. I load the datatables from various DBs and have a config file that I read to determine the primary keys I want to enforce on the given datatables. If the config doesn't contain a proper (non unique) primary key, how can I catch this event when applying the primary key to the datatable? Currently it appears that it allows me to apply the primary key, even though it is not unique....
DataTable dtbl = ds.Tables[t.tblname];
DataColumn[] pks = new DataColumn[t.Get_Key_Columns().Count];
int i = 0;
foreach(DataColumn c in dtbl.Columns)
{
if(t.Get_Key_Columns().Exists(delegate(App_Column ac)
{return (ac.column_name == c.ColumnName);}))
{
pks[i] = c;
i++;
}
}
try
{
dtbl.PrimaryKey = pks;
}
catch etc.......
Anyone point out what I am missing? Thanks