🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.ado
1 messages
1 total messages Started by Ney André de Mello Zunino Sat, 03 Jun 2006 15:43
Related record in master table
#288
Author: Ney André de Mello Zunino
Date: Sat, 03 Jun 2006 15:43
37 lines
2684 bytes
Hello.

In an application, I have a form which displays a master/detail 
relationship on 2 DBGrids. The underlying data set for both grids are 
TADOQuery objects. In order to synchronize the details grid with the 
currently selected record on the master grid, I use the master's data 
set's /AfterScroll/ event. The handler for that event first stores the 
id of the currently selected master record (to be used when inserting 
detail records), then used that id as a parameter to the details' query.

So far, so good. The problem comes when trying to add detail records. 
Here is the scenario: I open the form and click on a master record with 
no associated detail records. The first thing I noticed is that the 
details grid shows an empty row, even though there are no records. I 
suppose that's by design. Anyway, trying to enter information on that 
row and posting it would cause the following error:

   "You can not add or change a record because a related record is
    required in table Master Table"

Ok, so it is telling me that I need to provide the "foreign key" field 
(within quotes because, AFAICT, Access does not provide FK ref. 
integrity control). Because I also noticed that, once I started editing 
the columns on the grid, the details' datasource would change into the 
/dsInsert/ state, I added code to its /OnStateChange/ event that would 
put the ID of the selected master record into the "FK" field on the new 
detail record. However, when I try to post that new record, I still get 
the same error.

Would anybody be kind enough to help me understand this situation. I 
could understand the initial error, but I don't know why it persists 
even after I provide the id of the master record.

Thank you very much,

-- 
Ney Andr� de Mello Zunino
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads