Delphi adoquery Connection database query, insert, delete, modify

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.