开发者

How to check a number of inserted/modified records in TADOCommand?

开发者 https://www.devze.com 2023-03-14 05:35 出处:网络
I am using SQL Server database and after calling a simple SQL script I would like to know how many records were affected by开发者_JS百科 last (or only) executed statement in a script.

I am using SQL Server database and after calling a simple SQL script I would like to know how many records were affected by开发者_JS百科 last (or only) executed statement in a script.

I cannot find the reference how to achieve this in Delphi's TADOCommand and I know SQL Server gives this information to provider. I am aware of workarounds like getting @@ROWCOUNT in another query, yet this gives some overhead and unnecessary complexity.

Thanks.


Do you use the

function Execute(var RecordsAffected: Integer; const Parameters: OleVariant): _Recordset; 

version of the Execute method?

From the doc:

RecordsAffected indicates the number of records, if the command operates on data, that are affected by the command after execution.

So that should give you what you need.

Disclaimer: I cannot test this against SQL Server (don't have it).

0

精彩评论

暂无评论...
验证码 换一张
取 消