Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Unable to empty data set


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Feb 28, 2018 4:48 AM Last Post By: Eitan Arbel Threads: [ Previous | Next ]
Mark Williams

Posts: 120
Registered: 5/8/10
Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 6:45 AM
I am trying to delete rows in a query with the following code:

With FDQuery do begin
  BeginBatch;
       while not isEmpty do 
          Delete;
  EndBatch;
end;


The table has 3 rows. The second call to delete throws up an error "[FireDAC][DatS]-8. Cannot delete row".

I have tried calling Last/First after the call to Delete, but neither makes any difference.

The query has cachedUpdates set to true and EnableDelete=true

I appreciate that a call to EmptyDataSet will achieve what I am trying to do in the above code, but I am curious as to why I cannot delete more than one row in a loop.
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 6:58 AM   in response to: Mark Williams in response to: Mark Williams
I appreciate that a call to EmptyDataSet will achieve what I am trying to do in the above code, but I am curious as to why I cannot delete more than one row in a loop.
Maybe you have to Pass "True" in the BeginBatch Call.

procedure BeginBatch(AWithDelete: Boolean = False);
Mark Williams

Posts: 120
Registered: 5/8/10
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 7:33 AM   in response to: Robert Triest in response to: Robert Triest
Maybe you have to Pass "True" in the BeginBatch Call.

You do indeed. Hadn't noticed the optional param!

Many thanks
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 8:07 AM   in response to: Mark Williams in response to: Mark Williams
why aren't you using FDQuery.EmptyDataSet ?
what is better to use?
Mark Williams

Posts: 120
Registered: 5/8/10
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 10:16 AM   in response to: Eitan Arbel in response to: Eitan Arbel
I am, but I was just curious to know why my loop delete call was not working. Might want to delete more than one row, but less than all.
Michael Sawyer ...

Posts: 9
Registered: 9/10/17
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 12:22 AM   in response to: Eitan Arbel in response to: Eitan Arbel
Eitan Arbel wrote:
why aren't you using FDQuery.EmptyDataSet ?
what is better to use?

EmptyDataSet only deletes the records in your local Dataset, not the records in the table on your DBMS.
So if you call .Refresh after .EmptyDataset, you will get your data back.
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: Unable to empty data set  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 4:48 AM   in response to: Michael Sawyer ... in response to: Michael Sawyer ...
EmptyDataSet only deletes the records in your local Dataset, not the records in the table on your DBMS.
So if you call .Refresh after .EmptyDataset, you will get your data back.

oh wow that's a big "difference" then...

Thanks Michael
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02