Solved

Deleteing from some tables....

Posted on 2000-02-24
6
147 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

9 Experts available now in Live!

Get 1:1 Help Now