delphi与数据表之间修改和删除的操作

2025-04-12 08:55:32
推荐回答(1个)
回答(1):

第一步的答案已经和你说了。。。继续上面那部的设置。。放2个按钮。一个修改。一个删除 procedure TForm1.Button2Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from 你的表 where ID='''+edit1.Text+'''');
open;
if eof then
application.MessageBox('无法找到输入所ID的信息','提示信息')
else
begin
close;
sql.Clear;
sql.Add('update 你的表 set name='''+edit2.Text+''',sex='''+edit3.Text+''' where id='''+edit1.Text+'''');
execsql;
end;
end;
end;
修改按钮。。先判断是否存在这个ID.。然后进行修改 procedure TForm1.Button3Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from 你的表 where ID='''+edit1.Text+'''');
open;
if eof then
application.MessageBox('无法找到输入所ID的信息','提示信息')
else if messagedlg('确定要删除吗',mtconfirmation,[mbyes,mbno],0)=6 then
begin
close;
sql.Clear;
sql.Add('delete from 你的表 where ID='''+edit1.Text+'''');
execsql;
end;
end;
end; 删除键。。OK、、下班。。哈哈