delphi ADOQuery连接数据库的查询、插入、删除、修改  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi ADOQuery连接数据库的查询、插入、删除、修改


//查询记录
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('se lect * from YourTABLE where 查询条件');
ADOQuery.Open;
 
//插入记录
procedure TForm1.Button2Click(Sender: TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Text:='ins ert into YourTABLE(字段1,字段2) values(:字段1,:字段2)';
// ADOQuery.SQL.Add('ins ert into YourTABLE values(:字段1)');
ADOQuery.Parameters.ParamByName('字段1').Value:=trim(Edit1.Text);
ADOQuery.Parameters.ParamByName('字段2').Value:=trim(Edit2.Text);
ADOQuery.ExecSQL;
end;
//删除记录
procedure TForm1.Button3Click(Sender: TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Text:='Del ete from YourTABLE where 字段3=:字段3';
//这里没有添加where的条件判断,实际使用时,注意添加判断
// ADOQuery.SQL.Add('De lete from NEW_TABLE where 字段3=:字段3');
ADOQuery.Parameters.ParamByName('字段3').Value:=trim(Edit3.Text);
ADOQuery.ExecSQL;
//删除记录也可用DeleteRecords()函数
procedure DeleteRecords(AffectRecords: TAffectRecords = arAll);   
这个函数有一个参数:AffectRecords可以取如下的值:   
1、arCurrent :删除当前记录   
2、arFiltered :删除符合Filter过滤后的所有记录(如果你使用Filter过滤的话)   
3、arAll          :删除所有记录   
4、arAllChapters :Delete affects all chapters(ADO chapters)
//修改记录
procedure TForm1.Button4Click(Sender: TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Text:='Upd ate YourTABLE SET 字段4=:字段4';
//这里没有添加where的条件判断,实际使用时,注意添加判断
// ADOQuery.SQL.Add('Upd ate YourTABLE SET 字段4=:字段4');
ADOQuery.Parameters.ParamByName('字段4').Value:=trim(Edit4.Text);
ADOQuery.ExecSQL;
//即时更新插入、删除、修改后的记录
在上面插入、删除、修改的语句后添加如下代码即可:
ADOQuery.Close;
ADOQuery.SQL.Add('sele ct * from YourTABLE where 查询条件');
ADOQuery.Open;
//使用ADOQuery时注意:

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.042589902877808 seconds