Article View: borland.public.cppbuilder.database.ado
Article #288Related record in master table
From: Ney André de Mello Zunino
Date: Sat, 03 Jun 2006 15:43
Date: Sat, 03 Jun 2006 15:43
37 lines
2684 bytes
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
Technical Details
Message-ID:
<4481ad7d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10698b,c806b52b42761864,start X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII Date: Sat, 03 Jun 2006 12:43:56 -0300 From: Ney André de Mello Zunino <zunino@inf.ufsc.br> Organization: Universidade Federal de Santa Catarina User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: Related record in master table Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 200.247.146.200 Message-ID: <4481ad7d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1149349245 200.247.146.200 (3 Jun 2006 08:40:45 -0700) Lines: 37 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail