Delete dataset records?


I'v got sort of a problem, i'm using an MS Access database combined with a delphi program. I use the Datasource and the adoquery compontents to connect with the database.

Now i'm used to work with SQL so i know all the commands and such, but as far as i know you can only use these command to get records from de database (adoquery.sql.add('SELECT * FROM Table'))

now i already made the insert work (NOT with an sql command, is that even possible) i used:
adoquery.fieldname(name) := value;;
but now i want to delete a record, or all the record.

i tried a lot of things, but nothing works, these things i tried and i think it should be any of these, tried more but don't think that's even possibile:
ADOQuery.Delete;// database is blocked or something
ADOQuery.Post;// not really sure i need this
ADOquery.DeleteRecords(); // this gives an error something like it's not in the right context, but i don't know the right one..

So anybody knows how i delete records from de database?

Thanx in advance.


  • [b][red]This message was edited by bloodyangel at 2003-8-1 3:48:29[/red][/b][hr]
    Try this :

    with AdoQuery1 do
    if Active then Close;
    SQL.Add ('Delete from table');

    SQL is not only used for Selecting records but also used Inserting, Updating and Deleting data. The code above deletes all record in the table.If you want to perform conditional deletion then add a where statement like this :

    SQL.Add ('Delete From table where cost > 1000')
    The only thing you should care about is that you can not use 'TAdoQuery.Open' method with 'Insert, Update and Delete' queries. Use it only with 'Select' queries. ExecSQL method is what you should use with other 3(Insert, update and delete) queries.

    good luck...

  • Thanx that works.

    And i always used the so that is what always wend wrong.

    So thanx for the help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!