Calls to AddNew where there is a DataRelation

G

Greg

Our DataSource is a DataSet with 2 DataTables. Call them Table1 and Table2.

Table1 is the parent in a DataRelation to Table2. Table1's key is Field1
while Table2's key is Field2. So the DataRelation is Table1.Field1 to
Table2.Field2.

When we call AddNew on Table2 (the child), Table2's key, Field2, always
equals Table1.Field1. We tried setting DefaultValue on Table2.Field2,
however instead of the DefaultValue it is still Table1's Field1 value.

So it appears that the DataRelation forces the New, detached, DataRow to use
the parents key for it's key. Why?
 
M

Miha Markic

Hi Greg,

I think you are confusing fields a bit.

Both tables can have keys.
In Table1 -> it is Field1.
However, the Field2 in Table2 is not a key (though it can be) but it is a
parentId field (a value matching parentid) thus it is normal that they have
both the same value.
You might set Table2.Field1 as key and leave Field2 as is.

Does this clear things?
 
G

Greg

Actually, Table1.Field1 is not a key. It is a normal DataColumn with no
key. Table2.Field2 is a PrimaryKey however.


We create a DataRelation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top