无法关闭或打开并激活或停用ADOQuery1

时间:2014-11-12 15:08:48

标签: delphi ms-access

两个代码都能正常工作。但是不能ADOQuery1.close或ADOQuery1.open以及活动或非活动的ADOQuery1来查看更改。要查看更新的更改,我必须重新执行项目。 提前致谢

procedure TForm1.Button4Click(Sender: TObject);
begin    
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update new set net='''+Edit1.Text+''' ' );
ADOQuery1.SQL.Add('where code=16');
ADOQuery1.ExecSQL;


procedure TForm1.Button4Click(Sender: TObject);
begin 
ADOQuery1.Active:=false;
ADOQuery1.SQL.Text := 'update new set net=:num where code=16';
ADOQuery1.Parameters.ParamByName('num').Value := Edit1.Text;
ADOQuery1.ExecSQL;

1 个答案:

答案 0 :(得分:5)

每个方面

使用查询组件
SelectQuery.SQL.Text := 'SELECT * FROM new';
UpdateQuery.SQL.Text := 'UPDATE new SET net=:num WHERE code=16';

要更新记录,只需设置参数,执行UpdateQuery并刷新SelectQuery

procedure TForm1.Button4Click(Sender: TObject);
begin 
  UpdateQuery.Parameters.ParamByName('num').Value := Edit1.Text;
  UpdateQuery.ExecSQL;
  SelectQuery.Refresh;
end;

这很容易,简单甚至更快,因为在第一次执行UpdateQuery之后,语句已经准备好了。