Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Enterprise
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Getting a Count of the Rows Affected by a SQL Statement

SQL Server does not return a result set for action queries (SQL insert, update, or delete statements). If you were to use the SQLExecute method and execute the statement directly, RDO would catch the returning row count and make it available to you. However, since the statement is executed in a stored procedure, the row count information is not returned to ODBC. Hence, the Remote Data Object (RDO) can''t return this information.

If you run a stored procedure that contains a mix of select and action statements, and an action statement fails, an error is returned to RDO. The error comes back to VB in the form of a trappable data error, which you can handle with the On Error syntax. The only thing that is not available is the actual number of rows affected by the action statement because the SQL Server does not return this information to RDO. However, if your system must to know the actual number of rows affected, you can put:

 Select @@ROWCOUNT
after any action statements in the stored procedure. This produces a one-column, one-row result set containing the number of rows affected by the action statement. DBLib and ODBC API require the same procedure as RDO.
A. Nicklas
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date