我尝试了这个:
function TMyClass.removeRecords(...) : integer;
var
aC : TADOCommand;
aRS : _RecordSet;
begin
aC := createADOCommand;
try
aC.Connection := fConnection;
aC.commandText := getDeleteModelSQLCommand( ... );
aRS := aC.Execute;
{$ifdef debug_AlwaysOne}
result := 1;
{$else}
result := aRS.RecordCount;
{$endif}
finally
releaseADOCommand( aC );
end;
end;
在定义了
debug_AlwaysOne
条件的情况下,它可以正常运行。但是,在读取
RecordCount
的行上,将引发错误:关闭对象时不允许操作
有什么方法可以获取已删除记录的数量?我知道我可以在删除之前执行汇总查询。但是我可以在没有其他SQL命令调用的情况下执行此操作吗?
最佳答案
使用具有TADOCommand.Execute()
输出参数的RecordsEffected
的重载版本:
function Execute(var RecordsAffected: Integer; const Parameters: OleVariant): _Recordset; overload;
例如:
function TMyClass.removeRecords(...) : integer;
var
aC : TADOCommand;
begin
aC := createADOCommand;
try
aC.Connection := fConnection;
aC.commandText := getDeleteModelSQLCommand( ... );
{$ifdef debug_AlwaysOne}
aC.Execute;
Result := 1;
{$else}
aC.Execute(Result, EmptyParam);
{$endif}
finally
releaseADOCommand( aC );
end;
end;
关于delphi - 如何获得已删除记录的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42648784/