Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Delete dataset records? Posted by wisky on 1 Aug 2003 at 2:35 AM
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.
Report
Re: Delete dataset records? Posted by bloodyangel on 1 Aug 2003 at 3:46 AM
This message was edited by bloodyangel at 2003-8-1 3:48:29

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




Report
It work, thanx!! Posted by wisky on 1 Aug 2003 at 4:32 AM
Thanx that works.

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

So thanx for the help.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.