I'm executing a SQL UPDATE statement using a TADOQuery component and want to inspect the number of rows that were updated. The UPDATE statement is executing fine and the rows are modified accordingly but the .RowsAffected property always returns -1. The documentation states -1 indicates an error with the statement, but as I say it executes fine. I've tried prefixing the statement with SET NOCOUNT OFF but this made no difference. My code is as follows :
var
adoUpdateQuery: TADOQuery;
blnUpdatedOK: Boolean;
begin
adoUpdateQuery := TADOQuery.Create(nil);
adoUpdateQuery.DisableControls;
adoUpdateQuery.Connection := adcMiddleTierDB;
adoUpdateQuery.ExecuteOptions := [eoExecuteNoRecords];
adoUpdateQuery.SQL.Text := 'UPDATE MyTable SET Status = 1 WHERE Status = 0';
try
adoUpdateQuery.ExecSQL;
blnUpdatedOK := (adoUpdateQuery.RowsAffected > 0);
I'm using Delphi XE2, connecting to MS SQL Server 2008R2.