ADOQuery.Locate 更新
我有这样的代码:
begin
DM_SAMPriceCopy.Qy_Detail.First;
while not DM_SAMPriceCopy.Qy_Detail.Eof do
begin
if DM_SAMPriceCopy.Qy_Detail.Locate('ProcessID',QryDataDetail.FieldByName('ProcessID').AsInteger,[]) then
begin
QryDataDetail.Edit;
QryDataDetail.FieldByName('ActuallyPrice').AsFloat:=DM_SAMPriceCopy.Qy_Detail.FieldByName('ActuallyPrice').AsFloat;
QryDataDetail.Post;
end;
DM_SAMPriceCopy.Qy_Detail.Next;
end;
end;
将DM_SAMPriceCopy.Qy_Detail开启,然后用Locate定位相同的ProcessID,如果存在,则更新QryDataDetail的ActuallyPrice。但是我通过调试发现,它出现了死循环,Next之后,获取的ProcessID都是一样的。
请问该如何做?
[解决办法]
begin
DM_SAMPriceCopy.Qy_Detail.First;
while not DM_SAMPriceCopy.Qy_Detail.Eof do
begin
if DM_SAMPriceCopy.Qy_Detail.Locate('ProcessID',QryDataDetail.FieldByName('ProcessID').AsInteger,[]) then
begin
QryDataDetail.Edit;
QryDataDetail.FieldByName('ActuallyPrice').AsFloat:=DM_SAMPriceCopy.Qy_Detail.FieldByName('ActuallyPrice').AsFloat;
QryDataDetail.Post;
QryDataDetail.Next;
end;
DM_SAMPriceCopy.Qy_Detail.Next;
end;
end;