Solved

testing for an empty dataset before deleting a record

Posted on 1998-09-30
1
1,270 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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

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 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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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