請看下列源代碼有什么問題﹗(10分)

  • 主题发起人 主题发起人 mark_du
  • 开始时间 开始时间
M

mark_du

Unregistered / Unconfirmed
GUEST, unregistred user!
使用下列代碼發生錯誤﹕Row cannot be located for updating,Some values may have benn changed since it was last read!
源代碼絕確業沒有問題﹗
with SelectKq do
begin
first;
repeat
edit;
fDate:=FieldByName('wkdate').AsDateTime;
i:=strToint(formatDateTime('dd',fDate));
wkno := Fieldbyname('fwkno').asstring;
yyyymm :=MaskEdit1.text;
if i = 1 then //清除已有記錄
begin
DelRecDaily.SQL.Text := 'delete from EntryDaily where code ='+wkno+' and yyyymm = '+yyyymm;
DelRecDaily.Prepared;
DelRecDaily.ExecSQL;
end;
{EntryTable.close;
EntryTable.Parameters.ParamByName('yyyymm').value := trim(MaskEdit1.text);
EntryTable.Prepared;
EntryTable.open;}
EntryTable.Refresh;
if EntryTable.locate('code;yyyymm',VarArrayOf([wkno,yyyymm]),[loCaseInsensitive]) then
begin
EntryTable.edit;
EntryTable.FieldByName('f'+inttostr(i)+'1').AsString:=FieldByName('book_on').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'2').AsString:=FieldByName('lunch_out').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'3').AsString:=FieldByName('lunch_in').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'4').AsString:=FieldByName('book_off').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'5').AsString:=FieldByName('atime11').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'6').AsString:=FieldByName('atime21').AsString;
EntryTable.fieldByName('addtime').Asinteger:=EntryTable.fieldByName('addtime').Asinteger+fieldByName('addtime').Asinteger;
EntryTable.fieldByName('worktime').AsFloat:=EntryTable.fieldByName('worktime').Asinteger+fieldByName('worktime').Asinteger;
EntryTable.post;
end
else
begin
EntryTable.Insert;
EntryTable.FieldByName('code').AsString:=FieldByName('fwkno').AsString;
EntryTable.FieldByName('name').AsString:=FieldByName('fname').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'1').AsString:=FieldByName('book_on').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'2').AsString:=FieldByName('lunch_out').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'3').AsString:=FieldByName('lunch_in').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'4').AsString:=FieldByName('book_off').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'5').AsString:=FieldByName('atime11').AsString;
EntryTable.FieldByName('f'+inttostr(i)+'6').AsString:=FieldByName('atime21').AsString;
EntryTable.fieldByName('addtime').Asinteger:=EntryTable.fieldByName('addtime').Asinteger+fieldByName('addtime').AsInteger;
EntryTable.fieldByName('worktime').Asinteger:=EntryTable.fieldByName('worktime').AsInteger+fieldByName('worktime').AsInteger;
EntryTable.FieldByName('yyyymm').asstring := yyyymm;
EntryTable.post;
end;
next;
Gauge1.position :=Gauge1.position+1;
until eof;
 
老兄,代码我没看,不过碰过这个问题。当时我的解决办法是将表的关键字段读出来后
就不会出现了!
 
{EntryTable.close;
EntryTable.Parameters.ParamByName('yyyymm').value := trim(MaskEdit1.text);
EntryTable.Prepared;
EntryTable.open;}
說明﹕EntryTable.sql.text ='select * from entrydaily
應該是全部讀出了吧﹗
 
自己簡化一下代碼﹐進行測試吧
 
關代碼什么事﹖如果要幫忙就清楚點﹐不要不清不楚行嗎﹖
 
如你是采用SQLSERVER
1。有可能是你在设计字段时,设了默认值
2。有可能为没有初始化
 
兩個都不是﹗
再想想
 
老兄,表里面有没有关键字段??如果没有的话建议加一个自动增量字段!
你这样的代码我根本没办法运行!!!!!而且又这么多!!有点晕!!!
 
把edit 移到repeat循环外,把EntryTable.post也搬到repeat外,
我就想不明白,你对EntryTable操作完之后一块post 不行吗,干嘛insert一次post一次;
这样效率多低呀
 
這個我知道﹐要解決的問題沒解決﹐我暫進做測試用的﹗有沒有解決方法﹗~~
 
我現在改用緩存更新﹐問題已經全部解決﹐但如果緩存的記錄
達到500條時﹐在用EntryTable.UpdateBatch();時﹐提示﹕
"無法識別的錯誤﹗請問各位怎么回事﹖
 
后退
顶部