2
Answers

primary keys

chronics

chronics

17y
1.9k
1
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
Answers (2)
0
chronics

chronics

NA 4 0 17y
hi ted sorry bout the code layout. solved the problem i was adding the primary key declaration after defining the relationships between the tables rather than before defining the relationships between the tables. thanks
0
Ted Vasilopoulos

Ted Vasilopoulos

NA 10 0 17y
Hello,

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