我用locate 函数 定位记录(单条记录)并修改某个字段,假如我要找的记录正好是第一行或者是最后一行,它会准确的指向;如果在其他行,就会指向符合条件的那一行的下一行。那位大哥知道怎么回事? 或者推荐一个更好的方法,谢谢!PS:数据库是sql server 2000,用delphi 7
我用的例子,BookTbl.locate('bdate;baddr',vararrayof([date,addr]),[]);
我用的例子,BookTbl.locate('bdate;baddr',vararrayof([date,addr]),[]);
另外应该确保date,addr两个参数数据的正确性
begin
DatabaseName:='EXPDATA';
TableName:='StuStatus';
Open;
//IndexFieldNames:='StuNo;LessonNo';
//if not FindKey([StuNo,LessonNo]) then
// Response.SendRedirect('/kfsy/DLLHost/STUProc.dll/SShowMsg?MT=OpError&MC=DBQuery')
if not Locate('StuNo;LessonNo',VarArrayOf([StuNo,LessonNo]),[loPartialKey]) then
Response.SendRedirect('/kfsy/DLLHost/STUProc.dll/SShowMsg?MT=OpError&MC=DBQuery')
else
begin
Edit;
FieldByName('TimeLeft').AsString:=inttostr(strtoint(FieldByName('TimeLeft').AsString)-2);
Post;
end;
Close;
end;
with StatTable do
begin
DatabaseName:='EXPDATA';
TableName:='StuStatus';
Open;
if Locate('StuNo;LessonNo',VarArrayOf([StuNo,LessonNo]),[loPartialKey]) then
begin
Edit;
FieldByName('TimeLeft').AsString:=inttostr(strtoint(FieldByName('TimeLeft').AsString)-2);
Post;
end
else
Response.SendRedirect('/kfsy/DLLHost/STUProc.dll/SShowMsg?MT=OpError&MC=DBQuery')
Close;
end;
with StatTable do
begin
DatabaseName:='EXPDATA';
Close;
TableName:='StuStatus';
IndexFieldNames:='StuNo;LessonNo';
Open;
if FindKey([StuNo,LessonNo]) then
begin
Edit;
FieldValues['TimeLeft']:=inttostr(strtoint(FieldByName('TimeLeft').AsString) - 2);
Post; Close;
end
else Response.SendRedirect('/kfsy/DLLHost/STUProc.dll/SShowMsg?MT=OpError&MC=DBQuery');
end;