Deleting records according to certain criteria

I tried looking online but no luck How can I delete all entries in the adotable on button click that match different criteria. For example, I want to be able to delete all records in an adotable where Labour_ID (this is the name of the field inside the adotable) is DBedit.Text.

sorry this is a little vague, but suggestions would be appreciated. thank

+3


source to share


1 answer


You can delete lines with a simple loop:

while ADOTable1.Locate('Labour_ID', Edit1.Text, []) do
  ADOTable1.Delete;

      

Better still use TADOQuery, and do it using SQL:



ADOQuery1.SQL.Text := 'DELETE FROM YourTable WHERE Labour_ID = :Labour_ID';
ADOQuery1.Params.ParamByName('Labour_ID').AsString := Edit1.Text;
ADOQuery1.ExecSQL;

      

For the last parameter, LocateOptions

see the Delphi documentation on TDataSet.Locate . (Link to XE2 docs, but it hasn't changed much (if at all) for ADO since D7).

+8


source







All Articles