Problem with Master/Detail tables

Problem with Master/Detail tables

Post by Alveri » Thu, 27 Mar 2008 07:35:26


Hello everybody.
I use Delphi 2006, Access 2003, ADO. Provider is Microsoft.Jet.OLEDB.4.0.
I'm writing a stand alone application that uses two tables with
master/detail relationship.
I decided to use TADODataset. CursorLocation is clUseClient and CursorType
is ctStatic.
In the AfterOpen event of both ADODatasets I set
ADODataset.Properties['Update Criteria'].Value := adCriteriaKey;
Master primary key is based on two fields: Date (that is ftDateTime) and
Time (ftString).
Detail table contains the same two fields (Date and Time) and an index based
on those fields.
Master/detail relationship is consequently based on Date and Time.
In Access I set up the relation and I set also the referential integrity
with cascading update and cascading delete.
Everything worked fine during all the tests.
But one day I had to change the Date value of a record in the Master table
and here is my problem.
Date field in Detail table is NOT updated and the corresponding record
disappears from detail grid until I move back to the old Date value in the
master table. That is, the relation is broken for that record.
Why does this happen? What's wrong? If I do the same change of Date value
using Access instead of my application, the corresponding value in Detail
table is regularly updated.
Thanks for your help.

Alverio
 
 
 

Problem with Master/Detail tables

Post by Alveri » Fri, 28 Mar 2008 05:10:36

Thank you Brian.
In the OnChange event of the two fields that make the PrimaryKey in the
master table I put the following code:

ADODatasetDetail.Refresh;

But also in this case the record disappear from the detail grid if I change
the value of Date or Time.
Even if I put code in the above event to close and open again the detail
dataset I got the same result.
The only way is to close the application.
One solution could be adding an AutoInc field in the master table as primary
key and use that field to build the master/detail relation.
This field could not be change and in this way I solve the problem.
Then I could programatically check if the user is trying to post a master
record with and existing date and time (what is now controlled automatically
as they are the primary key). But I would like this to be the last option.
Any suggestion?



"Brian Bushay TeamB" < XXXX@XXXXX.COM > ha scritto nel messaggio

 
 
 

Problem with Master/Detail tables

Post by Alveri » Fri, 28 Mar 2008 15:01:21

Thanks a lot, Brian. Now it works properly. I don't why I used Refresh
instead of Requery...
But in any case I put code in the wrong event!

Ciao,
Alverio


"Brian Bushay TeamB" < XXXX@XXXXX.COM > ha scritto nel messaggio