//Query RecordsprocedureTform1.button1click (sender:tobject);beginAdoquery.close; ADOQuery.SQL.Clear; ADOQUERY.SQL.ADD ('SELECT * from yourtable where query condition'); Adoquery.open; //Inserting RecordsprocedureTform1.button2click (sender:tobject);beginAdoquery.close; ADOQuery.SQL.Clear; ADOQuery.SQL.Text:='INSERT into yourtable (field 1, Field 2) VALUES (: Field 1,: Field 2)';//ADOQuery.SQL.Add (' INSERT INTO yourtable values (: Field 1) ');ADOQuery.Parameters.ParamByName ('Field 1'). value:=trim (edit1.text); ADOQuery.Parameters.ParamByName ('Field 2'). value:=trim (edit2.text); Adoquery.execsql;End;//Deleting RecordsprocedureTform1.button3click (sender:tobject);beginAdoquery.close; ADOQuery.SQL.Clear; ADOQuery.SQL.Text:='Delete from yourtable where field 3 =: Field 3';//here does not add where the condition judgment, when actually used, pay attention to add judgment//ADOQuery.SQL.Add (' Delete from new_table where field 3 =: Field 3 ');ADOQuery.Parameters.ParamByName ('Field 3'). value:=trim (edit3.text); Adoquery.execsql;//Delete Record also available deleterecords () functionprocedureDeleterecords (affectrecords:taffectrecords =arAll); This function has a parameter: AffectRecords can take the following values:1, arcurrent: Deleting the current record2, arfiltered: Delete all records that match filter filter (if you use filter filtering)3, ArAll: Delete all records4, Arallchapters:delete affects all chapters (ADO chapters)//Modify a recordprocedureTform1.button4click (sender:tobject);beginAdoquery.close; ADOQuery.SQL.Clear; ADOQuery.SQL.Text:='Update yourtable SET Field 4 =: Field 4';//here does not add where the condition judgment, when actually used, pay attention to add judgment//ADOQuery.SQL.Add (' Update yourtable SET Field 4 =: Field 4 ');ADOQuery.Parameters.ParamByName ('Field 4'). value:=trim (edit4.text); Adoquery.execsql;//Instant update of inserted, deleted, Modified recordsAdd the following code after inserting, deleting, modifying the statement above: Adoquery.close; ADOQUERY.SQL.ADD ('SELECT * from yourtable where query condition'); Adoquery.open;//Note When using Adoquery:
1. query.requestlive must be true if you need to change the data
2, if there are input parameters, error prone, usually the wrong way:
For example: "WHERE ABC =: ABC"
Correct the following: "WHERE abc=:abc" means =: cannot leave spaces before or after.
3, Adoquery.open and Adoquery.execsql have different places.
Adoquery.open generally used in the query, select time, and Adoquery.execsql used in insert,delete,update and so on.
Original: http://www.cnblogs.com/lilongjiang/archive/2012/12/15/2819222.html
Delphi adoquery Connection database query, insert, delete, modify