Solved

Deleteing from some tables....

Posted on 2000-02-24
6
149 Views
Last Modified: 2010-04-04
I have made a simple database containing two tables, one is the master of the other.

The first one is a table of files. The second is a table of discs that these files are stored on.

Files.db and Discs.db.

I have a query for showing this in a TDBGrid with the SQL below:

Select Files.FileName, Discs.Label from Files, Discs
  where Files.Disc = Discs.ID
order by Files.FileName, Discs.Label

This query has an UpdateSQL connected to it.

I also have a separate Query for the discs with the following SQL:

Select ID, Label from Discs

This query is just for showing a list of the discs in a separate TDBGrid.

Now I want to be able to select a disc from the disc-grid and have my program to delete that disc from the database including all of its detail files. For this I have yet another query, the EraserQuery. Here's the SQL for that one:

Delete from Files
  where Disc = :CurrentDisc


"CurrentDisc" is defined below, it is for the program to know which disc the user has selected. -

procedure TModules.DiscQueryBeforeDelete(DataSet: TDataSet);
begin
  EraserQuery.ParamByName('CurrentDisc').AsInteger := Discs.FieldByName('ID').AsInteger;
  EraserQuery.Prepare;
  EraserQuery.ExecSQL;
end;


This works fine with the deletion and all, but it doesn't update the first query, the one showing all files and which disc they're on. It updates the tables and I have to restart my program for it to get updated. What can I do to fix this? Is there a better way deleting detailrecords?

regards,

Johan
0
Comment
Question by:sageryd
  • 2
  • 2
  • 2
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2555031
does a close and reopen of the first query not solve the problem without starting the whole app?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2555146
A Refresh should normally do fine.

(Question: Is the query updated when you move a record in the first table and then move back to the record)
0
 
LVL 1

Author Comment

by:sageryd
ID: 2555345
It works when i close and re-open the first query, but then I lose the selection the use might have. Is there another way? Refresh doesn't work.

johan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:ZifNab
ID: 2555365
Hi sageryd,

perhaps bookmarking it, before closing? (don't know if this works)

Or, get the recordnumber  (thus position of record)

and then after closing do a  

query.First (not needed I think)
query.MoveBy(recordnumber) ?

Zif.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 2555533
hi zif,

recordnumber is not on all databases properly filled,
also it is not properly filled, if not all records are fetched.

sageryd,
if zif suggestion will not work,
then save a unique fieldvalue into a var and
after open the query do a locate with it

meikl
0
 
LVL 1

Author Comment

by:sageryd
ID: 2555782
well, ok thanx! I guess Meikl should get the points as he was the first to give an answer.

Thanks again!


regards,

Johan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now