Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Delete dataset records?

wiskywisky Posts: 46Member
Hi,

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.insert;
adoquery.fieldname(name) := value;
adoquery.post;
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.

Comments

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

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

    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...




  • wiskywisky Posts: 46Member
    Thanx that works.

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

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