Z
zjwjw
Unregistered / Unconfirmed
GUEST, unregistred user!
我现在要对一个数据表用Adoquery进行选择并排序后,再用循环语句对结果集进行修改,
结果总是出现: dataset not in edit or insert mode.如何解决?
procedure .....
var temp1,temp2,temp3,temp4:integer;
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from tablename where ... order by field1');
open;
edit;
first;
temp1:=1;
temp2:=fieldbyname(field1).asinteger;
while not eof do //循环语句实现排名,将名次赋与field2
begin
temp3:=recno;
temp4:=fieldbyname(field1).asinteger;
if temp4=temp2 then
begin
fieldbyname(field2).asinteger:=temp1;
end
else
begin
fieldbyname(field2).asinteger:=temp3;
temp1:=temp3;
end;
temp2:=temp4;
next;
end;
close;
end;
end;
结果总是出现: dataset not in edit or insert mode.如何解决?
procedure .....
var temp1,temp2,temp3,temp4:integer;
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from tablename where ... order by field1');
open;
edit;
first;
temp1:=1;
temp2:=fieldbyname(field1).asinteger;
while not eof do //循环语句实现排名,将名次赋与field2
begin
temp3:=recno;
temp4:=fieldbyname(field1).asinteger;
if temp4=temp2 then
begin
fieldbyname(field2).asinteger:=temp1;
end
else
begin
fieldbyname(field2).asinteger:=temp3;
temp1:=temp3;
end;
temp2:=temp4;
next;
end;
close;
end;
end;