DELPHI6中的SQL UPDATE问题?(100分)

D

dilot7

Unregistered / Unconfirmed
GUEST, unregistred user!
【】一个ADO连接、一个ADOQUERY、一个DATASOURCE、一个按钮。
【】连接SQL服务器的数据库文件
【】以上OK
【】当按钮执行后,出现“ADOQUERY1:COMMANDTEXT DOES NOT RETURN A RESULT SET.”
【】语句如下:
procedure TForm1.Button1Click(Sender: TObject);
var ch_update :string;
begin
ch_update:= 'update test set test.abc1=test.abc2 where test.abc2=';
ch_update:=ch_update+'''bbbb1+''';
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add(ch_update);
adoquery1.Active:=true;
adoquery1.ExecSQL;
end;

end.
 
你的adoquery没设置能修改的模式
 
既然要插入记录
至少先要使表处在编辑(adoquery1.edit;)状态吧

procedure TForm1.Button1Click(Sender: TObject);
var ch_update :string;
begin
ch_update:= 'update test set test.abc1=test.abc2 where test.abc2=';
ch_update:=ch_update+'''bbbb1+''';
adoquery1.edit;//先加一句试试
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add(ch_update);
adoquery1.Active:=true;
adoquery1.ExecSQL;
end;

end.
 
加了一句【 adoquery1.edit;】后出现:

adoquery1:cannot perform this operation on a close dataset.
 
删掉这句:“adoquery1.edit
再删掉adoquery1.Active:=true;或 adoquery1.ExecSQL 其中的一句
因为这两句是同一个意思。

procedure TForm1.Button1Click(Sender: TObject);
var ch_update :string;
begin
ch_update:= 'update test set test.abc1=test.abc2 where test.abc2=';
ch_update:=ch_update+'''bbbb1+''';

adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add(ch_update);
adoquery1.Active:=true;

end;

end.
 
jihoo后一答复
出现“ADOQUERY1:COMMANDTEXT DOES NOT RETURN A RESULT SET.”
 
adoquery1.Active:=true;
相当于adoquery1.open
而你这句update是不会返回数据集的,只能用adoquery1.ExecSQL
所以会提示
ADOQUERY1:COMMANDTEXT DOES NOT RETURN A RESULT SET
把adoquery1.Active:=true;
这句去掉
 
是的,删除 adoquery1.Active:=true;
 
with adoquery1 do
being
Close;
SQL.Clear;
SQL.Add(ch_update);
ExecSQL;
end;
 
好像程序没有执行,数据库里的数据没有改变!
 
程序没有执行!
 
真的没人知道?
 
多人接受答案了。
 
你們有沒有搞錯啊,思路都錯了,你更新完了就不管了啊,
還得回到原來的樣子顯示數據啊,你讓ADO拿什么來顯示數據啊
procedure TForm1.Button1Click(Sender: TObject);
var ch_update :string;
begin
ch_update:= 'update test set test.abc1=test.abc2 where test.abc2=';
ch_update:=ch_update+'''bbbb1+''';
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add(ch_update);
adoquery1.ExecSQL;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from test');
adoquery1.open;
end;

end.

 
顶部