高手我快崩溃了,以下代码一直出现record cannot be located for updating since it was last read  错误,
能否帮忙解决一下?
 
for i:=1 to NullItemCount do
   begin
     IdCan:=MatList[NullList[i]].MatID;
     if DM.T_ForPscDetail.Locate('原料ID',IdCan,[]) then// DM.T_ForPscDetail为tadotable
     begin
       if DM.T_ForPscDetail.State<>dsEdit then
       DM.T_ForPscDetail.edit;
       DM.T_ForPscDetail.FieldByName('需要量').AsFloat:=x[i];
       DM.T_ForPscDetail.Post;
     end;
   end;
   if FItemCount>0 then   //只有有填充物时候,才执行
   begin
     IdCan:=FMatList[FNullList[1]].MatID;
     if DM.T_ForPscDetail.Locate('原料ID',IdCan,[]) then
     begin
       if DM.T_ForPscDetail.State<>dsEdit then
           DM.T_ForPscDetail.edit;
       DM.T_ForPscDetail.FieldByName('需要量').AsFloat:=fx;
       DM.T_ForPscDetail.Post;
     end;
   end;

解决方案 »

  1.   

    因为你的数据表中有内容相同的记录,最好在表中加一个自增长字段RecID以将每条记录区分开.
      

  2.   

    提交之后刷新一下数据集
           DM.T_ForPscDetail.FieldByName('需要量').AsFloat:=x[i];
           DM.T_ForPscDetail.Post;
           DM.T_ForPscDetail.close;
           DM.T_ForPscDetail.open;
         end;
       end;
       if FItemCount>0 then   //只有有填充物时候,才执行