Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to count the number of rows a DELETE statement impacts?

Status
Not open for further replies.

mluken

Programmer
Dec 31, 2003
54
US
I am trying to write a program that takes an UPDATE of DELETE sql statement and (without acually updating/deleting) find out how many (if any) rows the statement would modify if it were run. Any help would be greatly appreciated!!!!!

dim theConnection
set theConnection = Server.CreateObject("ADODB.Connection")
theConnection.ConnectionString = "DSN=myDSN"
theConnection.open
theSQL = "DELETE FROM ......"
theConnection.BeginTrans
theConnection.Execute(main_sql)
' HOW MANY ROWS DID THIS EFFECT???
theConnection.RollbackTrans
 
Why not do a
Code:
 SELECT Count(*)
?
If your theSQL is dynamic, you simply have to replace "DELETE" by "SELECT Count(*)".

Hope This Help
PH.
 
The .Execute method returns the number of rows affected so

Code:
Dim numRows
numRows = theConnection.Execute(main_sql)

HtH,

Rob

-Focus on the solution to the problem, not the obstacles in the way.-
 
I think I am getting closer, but now I get this error:

Wrong number of arguments or invalid property assignment

when I run this:

Dim numRows
numRows = theConnection.Execute(main_sql)
Response.write("TEST"&numRows)

ideas?
 
Sorry, the Command object returns the count in this manner. For the Connection object use...

Code:
Dim numRows
theConnection.Execute main_sql, numRows
Response.Write("Number of Rows=" & numRows)

numRows is a ByRef long value.

HtH,

Rob

-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top