I'm trying to modify some legacy ASP classic code, and I don't know much about ASP. How do I tell if a database Insert, Update, or Delete failed? By 'failed', I mean it either threw an error or affected zero rows.
Here's the code that was already in the ASP file that sets up the database connection:
On Error Resume Next
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=MSDAORA;Data Source=dbname;User Id=dbuser;Password=dbpw;"
There are a few Select statements that work like:
qry = "select stuff here..."
Set objRs = objConn.Execute(qry)
I understand how to get the results from the Select statements, but how do I get the results of a non-Select statement? Using a result set doesn't seem like it'd be the right way to do it. Or is it?
You may also use:
where,
con
is ConnectionSql
is your Command StringRecordsAffected
is count of Records AffectedUse the first
Execute
method parameter to get the rows affected:Using
adExecuteNoRecords
will gain performance according to several sourcesSource: Execute method in MSDN
You could use a transaction.
For INSERTs and UPDATEs the execution will return the number of rows affected, unless you set NO COUNT ON in your stored procedures. When you define a Command object calling its ExecuteNonQuery method will return that number to you. I use the return of those numbers (and whether they're non-zero) as an indication that it worked.