G
Greg
Because of a poor db design that supports the FoxPro app we are rewriting,
we are stuck working with an odd relation.
The parent table (in sql server 7.0) is a Member table and the child table
is an Address table. They link on Member.HomeAddress = Address.Control.
So, Member.HomeAddress = Address.Control, 1:1, in Sql Server.
In the client code, we have 2 DataTables (Member and Address) with a
DataRelation between them (Member.HomeAddress, Address.Control).
Calls to AddNew on the DataRelation cause the Address.Control DataColumn's
value to be set to the Member.HomeAddress's DataColumn's value.
So, if the Member.HomeAddress DataColumn's value = "123" and we call AddNew
on the DataRelation, the new Address DataRow's Control DataColumn's value
gets set to "123". I assume this happens because a DataRelation is 1:many
and it assumes there will be many Addresses with a control value of "123"
for the one Member record with that value in it's HomeAddress field.
I assume a ConstraintException is not thrown at this point since the new
Address DataRow has not been added to the row's collection.
Now, if we call EndCurrentEdit on the DataRelation, we get a
ConstraintException since "123" is already in the Address DataTable.
To get around this, we change the Member.HomeAddress DataColumn's value to a
dummy value and we also change the new Address DataRow Control DataColumn's
value to the same dummy value. Lets say the dummy value is "new". So the
Member.HomeAddress is set to "new" and the new Address DataRow Control
DataColumn's is set to "new". So, at this point the Member DataRow is
Modified and we have not added the Address DataRow to the rows collection.
Now here is where things get strange. We call EndCurrentEdit on Member and
the DataRelation. As soon as EndCurrentEdit executes, the new Address
DataRow gets added to the rows collection as expected. The modifed Member
DataRow's HomeAddress field is still storing "new" and we also have an Added
Address DataRow whose Control field is storing "new". All good so far.
However, for some unknown reason to me, the Member DataRow is relating to
the Address DataRow is was relating to prior to the call to AddNew ("123")
on the DataRelation. After the call to AddNew, the controls reflect the
values for the new DataRow (control = "new"). However, after the call to
EndCurrentEdit, the controls reflect the values for the UnChanged "123"
Address DataRow. The Member DataRow's HomeAddress field is still showing
"new" so I would assume the controls would show the values for the Address
DataRow whose control field = "new". But they do not, they show the values
for the Address DataRow whose control field = "123" (the 'old' Address
DataRow).
Thinking this was related to the DataRelation constraint, I set
EnforceConstraints to False. Same results though.
Why is this happening?
we are stuck working with an odd relation.
The parent table (in sql server 7.0) is a Member table and the child table
is an Address table. They link on Member.HomeAddress = Address.Control.
So, Member.HomeAddress = Address.Control, 1:1, in Sql Server.
In the client code, we have 2 DataTables (Member and Address) with a
DataRelation between them (Member.HomeAddress, Address.Control).
Calls to AddNew on the DataRelation cause the Address.Control DataColumn's
value to be set to the Member.HomeAddress's DataColumn's value.
So, if the Member.HomeAddress DataColumn's value = "123" and we call AddNew
on the DataRelation, the new Address DataRow's Control DataColumn's value
gets set to "123". I assume this happens because a DataRelation is 1:many
and it assumes there will be many Addresses with a control value of "123"
for the one Member record with that value in it's HomeAddress field.
I assume a ConstraintException is not thrown at this point since the new
Address DataRow has not been added to the row's collection.
Now, if we call EndCurrentEdit on the DataRelation, we get a
ConstraintException since "123" is already in the Address DataTable.
To get around this, we change the Member.HomeAddress DataColumn's value to a
dummy value and we also change the new Address DataRow Control DataColumn's
value to the same dummy value. Lets say the dummy value is "new". So the
Member.HomeAddress is set to "new" and the new Address DataRow Control
DataColumn's is set to "new". So, at this point the Member DataRow is
Modified and we have not added the Address DataRow to the rows collection.
Now here is where things get strange. We call EndCurrentEdit on Member and
the DataRelation. As soon as EndCurrentEdit executes, the new Address
DataRow gets added to the rows collection as expected. The modifed Member
DataRow's HomeAddress field is still storing "new" and we also have an Added
Address DataRow whose Control field is storing "new". All good so far.
However, for some unknown reason to me, the Member DataRow is relating to
the Address DataRow is was relating to prior to the call to AddNew ("123")
on the DataRelation. After the call to AddNew, the controls reflect the
values for the new DataRow (control = "new"). However, after the call to
EndCurrentEdit, the controls reflect the values for the UnChanged "123"
Address DataRow. The Member DataRow's HomeAddress field is still showing
"new" so I would assume the controls would show the values for the Address
DataRow whose control field = "new". But they do not, they show the values
for the Address DataRow whose control field = "123" (the 'old' Address
DataRow).
Thinking this was related to the DataRelation constraint, I set
EnforceConstraints to False. Same results though.
Why is this happening?