Article View: borland.public.cppbuilder.database.ado
Article #2803Help with related tables row insertion
From: Claudio Cavalli
Date: Fri, 21 Mar 2003 01:28
Date: Fri, 21 Mar 2003 01:28
44 lines
3257 bytes
3257 bytes
Hello, I am wondering if anyone has any suggestions as how to tackle this problem. I have a database that contains two related tables, Book and BookTitle. There is a one-to-many relationship between Book and BookTitle, where BookTitle contains the titles in different languages. The primary key in Book is the field BookID (a bigint that auto- increments for each new book added), while BookTitle's primary key is composed of the BookID (as a foreing key from Book) and the field BookTitleID, a tinyint that autoincrements for each new title added for a particular BookID. I have a form that displays the information about a book using ADO components. On this form I have a DBGrid that displays the various titles of the book. This works fine when displaying or updating information about an existing book. I run into problems when I try addding a book. The problem arises because when I edit the titles Grid, I generate an exception because the row for the Book table has not been added yet, and therefore trying to add a title in the BookTitle table violates the structure of the database. I have tried to go around this problem by creating a TEdit component into which I can enter an "initial" title for the book and disabling the title grid. The thought being that I would code in the AfterPost event for the DataSet for the Book table to enable the grid, and copying the title from the TEdit component into the BookTitle table. In addition I need to write code to change the Value of the TEdit component everytime the DataSet scrolls to a new record. I wrote the code in the AfterScroll event of the Book Dataset. At this point I realized that this would cause problems if I ever reused the DataSet when my form did not exist anymore (all of my DB access components are in a DataModule). The reason is that the DataSet accesses the TEdit component that is specifically on the form that I am using. Is there a more elegant way of solving this problem? Best Regards Claudio Cavalli P.S. Is there a good book out there that covers in detail how to use the DataBase components in C++Builder? I have both the C++Bulider 6 Developer's Guides, but they do not go into very much detail on how to use these components.
Technical Details
Message-ID:
<3e7a6ab2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,77297450500bf1ce,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-03-20 17:39:03 PST From: "Claudio Cavalli" <claudiocavalli@mindspring.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: Help with related tables row insertion Date: Thu, 20 Mar 2003 20:28:26 -0500 Lines: 46 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 4.35.92.111 Message-ID: <3e7a6ab2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1048210098 4.35.92.111 (20 Mar 2003 17:28:18 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail