Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Master-detail relationship

Posted on 2000-04-08
10
Medium Priority
?
234 Views
Last Modified: 2010-04-04
Hi,

I have database app that has a master table with several detail tables. The link is through the a field called "title".

When I edit this the title in the master table, how do I make it so that the change of title is reflected in the detail tables?

At the moment when I change the title in the master table, a new record is added in the detail tables rather than the old record being modified. This causes data associated with the old title to become "lost".

Thanks

John
0
Comment
Question by:JohnE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Expert Comment

by:efj67
ID: 2697399
I'm not sure I understand. Let me get this, you have a relational link with several child tables, but when you change the linking data you want the change to be reflected in the child tables? You will have to do some coding to accomplish this.

1. First you want to capture the linking data as it is presently in a variable.

2. Put the new info in a variable also.

3. Then use a decision statement to change data records in the child tables.

Your code might look something like this

var

oldinfo : <datatype>
newifo : <datatype>

begin
editnewinfofield.text:=newinfo;
oldinfo:=dbeditfield.value;
firstchildtable.open;
firstchildtable.first;
while firstchildtable not eof
 do
  begin
   if firstchildtablefield=oldinfo then
   begin
    firstchildtablefield.vaule:=newinfo;
    firstchildtablefield.post;
   else
    firstchildtablefield.next;
   end;
end;
end.


Note you may want to add some safety features in this code to insure that the integrity of the tables is maintained. If you are planning to network this app, this should be an offline batch operation.

I do realize this is rather bland but it should get the brain cooking.

Feel free to e-mail if I am off target.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2697435
for what database you need this?
0
 

Author Comment

by:JohnE
ID: 2697519
Initially it was for paradox tables, but I have migrated to DBISAM.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2704718
hi johne,

i am not familiar with dbisam, therefore i don't know,
if there could be done a constraint for modify forwarding at databaselevel.

in this case, you can(must) it do in the way, which  efj67 suggested, also if there are errors ( efj67 you've forgotten to edit the detailtable)

meikl
0
 

Author Comment

by:JohnE
ID: 2707616
Hi,

Below is some code based on what you suggested. This works, but only for the first instance of the title occuring in the secondary table.

If the title occurs more than once, only one instance is converted to the new title.

How can I make all instances change?

Table 1{master table}
Table 2{detail table}
Table 3{same table as 2, but without m/d link}

Thanks

John

procedure TForm1.UpdateClick(Sender:
TObject);
var
   oldinfo : string;
   newinfo : string;
begin
     Table1.Edit;
     Table2.close;
     Table1.post;
     newinfo := DBEdit1.text;
     oldinfo:= Edit1.Text;
with Table3 do      
begin
          first;
          open;
          edit;
          FindKey([Table1.FieldbyName('Title').AsString]);
          begin
          while not Eof do
            begin
                if Fields[0].AsString =oldinfo then
                   begin
                       Fields[0].AsString:=newinfo;
                       post ;
                       next;
                    end
            else
                next;
                Edit;
            end;
          end;
    end;
   Table2.open;
end;
0
 

Author Comment

by:JohnE
ID: 2707666
Hi,

Below is some code based on what you suggested. This works, but only for the first instance of the title occuring in the secondary table.

If the title occurs more than once, only one instance is converted to the new title.

How can I make all instances change?

Table 1{master table}
Table 2{detail table}
Table 3{same table as 2, but without m/d link}

Thanks

John

procedure TForm1.UpdateClick(Sender:
TObject);
var
   oldinfo : string;
   newinfo : string;
begin
     Table1.Edit;
     Table2.close;
     Table1.post;
     newinfo := DBEdit1.text;
     oldinfo:= Edit1.Text;
with Table3 do      
begin
          first;
          open;
          edit;
          FindKey([Table1.FieldbyName('Title').AsString]);
          begin
          while not Eof do
            begin
                if Fields[0].AsString =oldinfo then
                   begin
                       Fields[0].AsString:=newinfo;
                       post ;
                       next;
                    end
            else
                next;
                Edit;
            end;
          end;
    end;
   Table2.open;
end;
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 800 total points
ID: 2707702
hi johne,

did you thought about to use a query
(if possible with dbisam)

the statement is like

Update YourDetailTableName Set YourFieldName = YourNewValue Where YourFieldName = YourOldValue

and fire the statement with the query.ExecSQL-method

its much less code(if parametewrs are used) and its faster than iterating through the table

meikl
0
 

Expert Comment

by:floriangrimm
ID: 2707881
thats really good idea!!!
0
 

Author Comment

by:JohnE
ID: 2711198
Meikl,

Your SQL suggestion worked perfectly; and you're right - half the code and heaps faster.

How do I give you the points?

Thanks for your help.

John
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2711243
hi johne,

>How do I give you the points?
you've just done it

glad that you get it work
thanks for accepting my comment as answer
good luck again

meikl ;-)
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question