FireDAC.Comp.Client.TFDCustomCommand.RowsAffected

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property RowsAffected: TFDCounter read FRowsAffected;

C++

__property int RowsAffected = {read=FRowsAffected, nodefault};

Properties

Type Visibility Source Unit Parent
property public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomCommand

Description

Returns the number of rows operated upon by the latest query execution.

Inspect RowsAffected to determine how many rows were inserted, updated, deleted or fetched by the last command operation. If no rows were processed, RowsAffected = 0. If the numbers of processed rows are not accessible, RowsAffected = –1.

For MS SQL Server, RowsAffected may be unexpectedly equal to -1, if the stored procedure or the table trigger omits SET NOCOUNT ON. Check BOL for more details.

Example

procedure TForm1.ADCommand1AfterExecute(ASender: TObject);
begin
  if ADCommand1.RowsAffected = -1 then
    StatusBar1.SimpleText := 'Ok'
  else
    case ADCommand1.CommandKind of
    skDelete: StatusBar1.SimpleText := Format('%d rows deleted', [ADCommand1.RowsAffected]);
    skInsert: StatusBar1.SimpleText := Format('%d rows inserted', [ADCommand1.RowsAffected]);
    skUpdate: StatusBar1.SimpleText := Format('%d rows updated', [ADCommand1.RowsAffected]);
    else      StatusBar1.SimpleText := Format('%d rows affected', [ADCommand1.RowsAffected]);
    end;
end;

See Also