1 (edited by mgoodman99 2022-03-25 13:58:13)

Topic: Delete All Rows...then Auto Query

i want to delete all rows in table (not the table).  From a Button I use the Action, 'SQL Query', "Delete FROM userAnswers";

if i select the 2 table options below i get this error (see attachment).
i also get the same errors if i run it directly from a Script.

form1.tablegrid2.dbSQL := 'Delete From userAnswers';
form1.tablegrid2.dbSQLExecute;

If i leave these 2 options blank, no error and the data rows ARE deleted from db Table... BUT the TableGrid2 component doesnt run the Auto Query

even though the db Table doesnt have data, I still want to Column Names to appear in my TableGrid.

i did OnClick precedure from the same Button and ran
if Form1.TableGrid2.dbSQL <> '' then Form1.TableGrid2.dbSQLExecute; 

but still same result, doesnt auto update

what the best solution?  thanks

Post's attachments

Attachment icon myvdb_Delete From.png 61.71 kb, 97 downloads since 2022-03-25 

Re: Delete All Rows...then Auto Query

Hi,
I'd put your instructions in the script rather than use SQLQUERY (which is more suited for single statements).
Try it something like the attached.
There are two options;
1.  a simple delete everything from the table irrespective of what might be showing in the tablegrid
2.  a more selective delete where you only delete the rows from the table that are filtered in the tablegrid.
I guess it all depends on your exact requirement as to which suits best.
Derek.

Post's attachments

Attachment icon mgoodman.zip 573.22 kb, 239 downloads since 2022-03-25 

Re: Delete All Rows...then Auto Query

thanks for the reply.  doing a Tablegrid delete makes it more robust, id probably post on how to do it in the future so you saved both of us some time smile  thanks again

Re: Delete All Rows...then Auto Query

This delete whole rows from the tablegrid  but how can we delete selected row in a tablegrid.

Re: Delete All Rows...then Auto Query

Hi,
Not quite sure if this is what you're after (see attached).
In the attachment, there are now 3 options to delete data from a table;
1.  Button (DELETE FROM TABLE) - deletes ALL data irrespective of what is displayed in form1.tablegrid1.
2.  Button (DELETE FROM GRID) - deletes all data that is displayed in the grid (may be filtered).
3.  Button (DELETE CHECKED) - deletes only those rows that have been checked.
Derek.

Post's attachments

Attachment icon table deletion options.zip 577.1 kb, 200 downloads since 2022-06-20