應該直接對ADOQuery1修改ADOQuery1.Close; ADOQuery1.Sql.Text := 'Update XXXTable set YYYField = A'; AdoQuery1.Execute;
'Update Table set Field = A'
procedure TForm12.Button1Click(Sender: TObject); var tno,recno:integer; var tleixing,sno:string; var tpanduan:integer; begin tleixing:='选择题'; sno:=edit1.Text; with dm.pingfen do begin close; sql.Clear; sql.Add('select * from test where sno=:q1 and tleixing=:q2'); params[0].AsString:=sno; params[1].AsString:=tleixing; open; end;if radiobutton1.Checked then begin //recno:=select(sno,tleixing); recno:=dm.pingfen.RecordCount; if recno=0 then begin if application.MessageBox('该考生在考试安排中吗?','提示',mb_okcancel) =mrok then application.MessageBox('该考生缺考,成绩作零分计算','提示',mb_ok) else application.MessageBox('请重新输入考生学号!','提示',mb_ok); edit1.Text:=''; exit; end; tno:=1; while not dm.pingfen.eof do begin
if trim(dm.pingfen.FieldByName('tanswer').Value)=trim(dm.pingfen.FieldByName('tjieda').Value) then begin tpanduan:=1; with dm.pingfen1 do begin close; sql.Clear; sql.Add('update test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4'); params[0].AsInteger :=tpanduan; params[1].AsString:=sno; params[2].AsString:=tleixing; params[3].AsInteger:=tno; execsql; end; tno:=tno+1; end else begin tpanduan:=0; with dm.pingfen1 do begin close; sql.Clear; sql.Add('update test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4'); params[0].AsInteger :=tpanduan; params[1].AsString:=sno; params[2].AsString:=tleixing; params[3].AsInteger:=tno; execsql; end; tno:=tno+1; end;
dm.pingfen.Next;
end; end; end;
ADOQuery1是通过SELECT语句查找过滤出来的(通过几次的条件设定后),怎么可以用'Update XXXTable set YYYField = A';此方法要指定某个表,是对整个表进行UPDATE的。
ADOQuery1.Sql.Text := 'Update XXXTable set YYYField = A';
AdoQuery1.Execute;
var tno,recno:integer;
var tleixing,sno:string;
var tpanduan:integer;
begin
tleixing:='选择题';
sno:=edit1.Text;
with dm.pingfen do
begin
close;
sql.Clear;
sql.Add('select * from test where sno=:q1 and tleixing=:q2');
params[0].AsString:=sno;
params[1].AsString:=tleixing;
open;
end;if radiobutton1.Checked then
begin
//recno:=select(sno,tleixing);
recno:=dm.pingfen.RecordCount;
if recno=0 then
begin
if application.MessageBox('该考生在考试安排中吗?','提示',mb_okcancel) =mrok then
application.MessageBox('该考生缺考,成绩作零分计算','提示',mb_ok)
else
application.MessageBox('请重新输入考生学号!','提示',mb_ok);
edit1.Text:='';
exit;
end; tno:=1;
while not dm.pingfen.eof do
begin
if trim(dm.pingfen.FieldByName('tanswer').Value)=trim(dm.pingfen.FieldByName('tjieda').Value) then
begin
tpanduan:=1;
with dm.pingfen1 do
begin
close;
sql.Clear;
sql.Add('update test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
params[0].AsInteger :=tpanduan;
params[1].AsString:=sno;
params[2].AsString:=tleixing;
params[3].AsInteger:=tno;
execsql;
end;
tno:=tno+1;
end
else
begin
tpanduan:=0;
with dm.pingfen1 do
begin
close;
sql.Clear;
sql.Add('update test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
params[0].AsInteger :=tpanduan;
params[1].AsString:=sno;
params[2].AsString:=tleixing;
params[3].AsInteger:=tno;
execsql;
end;
tno:=tno+1;
end;
dm.pingfen.Next;
end;
end; end;