使用TDatabase控件 query1.databasename :=database1.databasename; with Query1 do begin try Database1.StartTransaction; if active then close; sql.text := 'select * from 表1 where rkey=1 for update nowait'; ExecSQL; {do some other sql you want;} Database1.Commit; {on success, commit the changes}; Except Database1.Rollback; {on failure, undo the changes}; ShowMessage('该记录被另一用户锁定!' ); Exit; End;
query1.databasename :=database1.databasename; with Query1 do
begin
try
Database1.StartTransaction;
if active then close;
sql.text := 'select * from 表1 where rkey=1 for update nowait';
ExecSQL;
{do some other sql you want;}
Database1.Commit; {on success, commit the changes};
Except
Database1.Rollback; {on failure, undo the changes};
ShowMessage('该记录被另一用户锁定!' );
Exit;
End;