primary keys
When i use the code below to add a datarelation to 2 tables named 'Category' and 'Product' and then try to find a row within the tables using the find method shown below I get the error 'Table doesnt have a Primary Key'.
DataRelation catAndProdDataRelation = new DataRelation("CategoryAndProductDataRelation", ds.Tables["Category"].Columns[0]
, ds.Tables["Product"].Columns[3], true);
ds.Relations.Add(catAndProdDataRelation);
DataRow cdr = ds.Tables["Category"].Rows.Find(id);
I have also tried adding the primary keys explicitly with
ds.Tables["Category"].Constraints.Add("PK_ColumnID", ds.Tables["Category"].Columns[0], true);
ds.Tables["Product"].Constraints.Add("PK_ProductID", ds.Tables["Product"].Columns[0], true);
I get the error constraint matches constraint 1 already in collection
I thought the datarelation created the primary keys and the constraint matches error seems to indicate that.
Any help much appreciated
chronicsPosted May 21, 2007, 12:54 PM
Ted VasilopoulosPosted May 14, 2007, 8:56 AM
I would love to help you out, but could you possibly past your code a little better?
Try line by line and I will have a look at it.
TedManowar