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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error message on execute SQL statement

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
AP
Hi guys...
e.g. i have 3 SQL insert statement:
SQL1,SQL2, SQL3.

During execution , if one of the sql is not successfully execute, i want to rollback the transaction and give error message to the user. how to do that?

Thanks
 
use
on error resume next statement

and in the next statement use
rs.CancelUpdate

webspy

 
on error resume next
'statement

if err.number <> 0
'rollback transaction here because there was an error
err.clear
end if

on error goto 0 'turns error checking back on

:)
Paul Prewett
penny.gif
penny.gif
 
Use ADO Transactions. From my teaching manual...

&quot;A transaction is a group of statements that must all succeed in order to be committed. If any statement fails, the transaction in rolled back.&quot;

Example...

*****
intErrors = 0
set objConn = Server.CreateObject (&quot;ADODB.COnnection&quot;)
objConn.OPen &quot;BankDB&quot;
objConn.BeginTrans
strSQL = &quot;Update SavingsAccount SET Amt = Amt - &quot; & Amt & &quot;WHERE SavingsAccountNumber = &quot; & SavingsAccountNumber
objConn.Execute strSQL
intErrors = intErrors + objCOnn.Errors.Count
strSQL = &quot;UPDATE CUrrentAccount SET Amt = Amt + &quot; & Amt & &quot; WHERE CurrentAccountNumber = &quot; & CurrentAccountNumber
objConn.Execute strSQL
intErrors = intErrors + objConn.Errors.Count
If intErrors = 0 Then
objConn.CommitTrans
Else
objConn.RollbackTrans
End If
objConn.Close
set objConn = Nothing
*****

Hope this helps you.

G -GTM Solutions, Home of USITE-
-=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top