如何获取已删除记录的数量?
How can I get the number of deleted records?
我试过这个:
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
的那一行,它引发了一个错误:
Operation is not allowed when the object is closed
有什么方法可以得到删除的记录数吗?我知道我可以在删除前执行聚合查询。但是我可以在没有另一个 SQL 命令调用的情况下执行此操作吗?
使用具有 RecordsEffected
输出参数的 TADOCommand.Execute()
的重载版本:
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;
我试过这个:
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
的那一行,它引发了一个错误:
Operation is not allowed when the object is closed
有什么方法可以得到删除的记录数吗?我知道我可以在删除前执行聚合查询。但是我可以在没有另一个 SQL 命令调用的情况下执行此操作吗?
使用具有 RecordsEffected
输出参数的 TADOCommand.Execute()
的重载版本:
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;