Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

testing for an empty dataset before deleting a record

Posted on 1998-09-30
1
Medium Priority
?
1,304 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

715 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