Delphi adoquery Connection database query, insert, delete, modify

Source: Internet
Author: User

//查询记录procedureTForm1.Button1Click(Sender: TObject);beginADOQuery.Close;ADOQuery.SQL.Clear;ADOQuery.SQL.Add(‘select * from YourTABLE where 查询条件‘);ADOQuery.Open;//插入记录procedureTForm1.Button2Click(Sender: TObject);beginADOQuery.Close;ADOQuery.SQL.Clear;ADOQuery.SQL.Text:=‘insert into YourTABLE(字段1,字段2) values(:字段1,:字段2)‘;// ADOQuery.SQL.Add(‘insert into YourTABLE values(:字段1)‘);ADOQuery.Parameters.ParamByName(‘字段1‘).Value:=trim(Edit1.Text);ADOQuery.Parameters.ParamByName(‘字段2‘).Value:=trim(Edit2.Text);ADOQuery.ExecSQL;end;//删除记录procedureTForm1.Button3Click(Sender: TObject);beginADOQuery.Close;ADOQuery.SQL.Clear;ADOQuery.SQL.Text:=‘Delete from YourTABLE where 字段3=:字段3‘;//这里没有添加where的条件判断,实际使用时,注意添加判断// ADOQuery.SQL.Add(‘Delete from NEW_TABLE where 字段3=:字段3‘);ADOQuery.Parameters.ParamByName(‘字段3‘).Value:=trim(Edit3.Text);ADOQuery.ExecSQL;//删除记录也可用DeleteRecords()函数procedureDeleteRecords(AffectRecords: TAffectRecords = arAll);   这个函数有一个参数:AffectRecords可以取如下的值:   1、arCurrent :删除当前记录   2、arFiltered :删除符合Filter过滤后的所有记录(如果你使用Filter过滤的话)   3、arAll          :删除所有记录   4、arAllChapters :Delete affects all chapters(ADO chapters)//修改记录procedureTForm1.Button4Click(Sender: TObject);beginADOQuery.Close;ADOQuery.SQL.Clear;ADOQuery.SQL.Text:=‘Update YourTABLE SET 字段4=:字段4‘;//这里没有添加where的条件判断,实际使用时,注意添加判断// ADOQuery.SQL.Add(‘Update YourTABLE SET 字段4=:字段4‘);ADOQuery.Parameters.ParamByName(‘字段4‘).Value:=trim(Edit4.Text);ADOQuery.ExecSQL;//即时更新插入、删除、修改后的记录在上面插入、删除、修改的语句后添加如下代码即可:ADOQuery.Close;ADOQuery.SQL.Add(‘select * from YourTABLE where 查询条件‘);ADOQuery.Open;//使用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.

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.