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时注意:

相关阅读 >>

Delphi处理http请求自定义header

Delphi提取网页中的图片

Delphi 查看字符串在不同编码(ascii、unicode、utf7、utf8、default、bigendianunicode)下的 hex

Delphi tstreamwriter快速写入文件

Delphi 程序退出时删除自身

ttreeview的两个事件ondragdrop、ondragover 实现自动拖放功能

Delphi下ado的多线程编程

Delphi tradiogroup 单选分组框组件

Delphixe4 版本中,已针对移动平台 引入了 arc 模型

Delphi里实现彩色图片转为黑白图像的功能

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...