Solved

testing for an empty dataset before deleting a record

Posted on 1998-09-30
1
1,284 Views
Last Modified: 2006-11-17
How can i test if the dataset is empty before allowing an button click event to delete a record?

If it is empty i want to respond with an appropriate dialog box, but i can't figure out an effective way to check first that it doesn't happen to be empty

any clues?
0
Comment
Question by:npepper
[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
1 Comment
 

Accepted Solution

by:
dejohn99 earned 50 total points
ID: 1341295
Either of these should work.

Wherever I have used DataSet1.Delete, you should put your normal Delete processing, whatever it may be.

procedure btnDelete1Click (Sender: TComponent)
begin
    if DataSet1.RecordCount = 0 then
        raise Exception.Create ('Dataset '+DataSet1.Name+' is empty');

    DataSet1.Delete;
end;



procedure btnDelete2Click (Sender: TComponent)
begin
    if DataSet1.RecordCount = 0 then
        MessageDlg ('Dataset '+DataSet1.Name+' is empty',
            mtError, [ mbCancel ], 0);
    else
        DataSet1.Delete;
end;


If you are concerned that the RecordCount may not be kept current, you might try this:

procedure btnDelete3Click (Sender: TComponent)
begin
        { EOF and BOF will only both be true for an empty dataset }
        if DataSet1.EOF and DataSet1.BOF then
            MessageDlg ('Dataset '+DataSet1.Name+' is empty',
                mtError, [ mbCancel ], 0)
        else
            DataSet1.Delete;
end;


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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