08.11.06

Rows affected by a querry in VB6?

Posted in TSQL, Visual Basic 6 at 9:11 pm by Hedwig Lodrigo

For some reason you would like to know how many records where affected by your sql statement called from visual basic 6. But you have no clue how to do it.

This is how you do it.

When you do a query in sql server then you can see how many rows where affected by it, because sql server fills up the @@rowcount variable.

Code:

delete from customer where name like 'A%'
print @@rowcount

If you want to return this result to a result set you can do the following:

Code:

delete from customer where name like 'A%'
select @@rowcount as affected

Then in visual basic 6:

dim newrs as ADODB.Recordset
Set newrs = rs.NextRecordset
msgbox newrs.Fields("affected")

Leave a Comment