Rows affected after update

whpgabesz
whpgabesz used Ask the Experts™
on
I am using delphi adocommand to update a table.
For example :
adocommand.commandtext := 'Update table set something = 'green'';

How can I get back the affected rows?
I am using ms Sql 2005.
Please write an example.
Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

Commented:
use a TAdoQuery instead
it has a property RowsAffected for this

Author

Commented:
Can you write an example?
Oracle dba
Top Expert 2009
Commented:
procedure TForm1.BitBtn1Click(Sender: TObject);
var qry: TADOQuery;
begin
  qry := TAdoQuery.Create(Self);
  try
    qry.ConnectionString := 'Your standard sql server connection string';
    // something like 'Provider=OraOLEDB.Oracle.1;Password=guessme;Persist Security Info=True;User ID=username;Data Source=DB'
    qry.SQL.Text := 'Update table set something = 'green'';
    qry.Execute;
    ShowMessage(Format('Rows Affected : %d', [qry.RowsAffected]));
  finally
    qry.Free;
  end;
end;
You can do...


adocommand.commandtext := 'Update table set something = 'green'';
adocommand.ExecSQL;
YourRowsAffected := adocommand.RowsAffected;

or shorter

adocommand.commandtext := 'Update table set something = 'green'';
YourRowsAffected := adocommand.ExecSQL;

Author

Commented:
It was an excellent answer. Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial