ASP » ObjectContext » SetComplete

Syntax:
ObjectContext.SetComplete

The SetComplete method declares that the transaction has been completed and resources can be updated.

The SetComplete method declares that the transaction of this object has been completed. In order for a transaction to be successfully completed, all individual components of the transaction must also be completed and have called SetComplete. By default, a script is considered to be completed if it runs to conclusion and does not abort. Therefore, in many cases, it may not be necessary to call SetComplete from the script.

If it exists, the OnTransactionCommit event is processed.

Examples

Code:
------------------------File1.asp-------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="File2.asp" method="POST">
ProductID:<input type="Text" name="ProductID">
Product Name:<input type="Text" name="Name">
Quantity Wanted:<input type="Text" name="Order">
<input type="Submit" name="Submit" value="Submit">
</form>
</BODY>
</HTML>
 
------------------------File2.asp-------------------
<%
@Transaction = "Required"
set connDB=server.createobject("adodb.connection")
connDB.Open "products", "", ""
productID = Response.Form("ProductID")
mySQL="Select * from products Where productID = " & productID
Set rsProductSrch = Server.CreateObject("ADODB.Recordset")
rsProductSrch.Open mySQL, connDB, adOpenStatic, adLockPessimistic
If rsProductSrch.BOF Or rsProductSrch.EOF Then
    ObjectContext.SetAbort
ElseIf rsProductSrch.Fields("Quanity") < Response.Form("Order") Then
    Response.Write "There is not enough in stock to give the present order. There are " & rsProductSrch.Fields("Quanity") & "."
    ObjectContext.SetAbort
Else
    rsProductSrch.Fields("Quanity") = rsProductSrch.Fields("Quanity") -
            Request.Form("Order")
    rsProductSrch.Update
    ObjectContext.SetComplete
End If
rsProductSrch.Close
connDB.Close
%>
 
Sub OnTransactionAborted()
Response.Write "The transaction aborted because there was not enough quantity on hand to fill your order."
End Sub
 
Sub OnTransactionCommit()
Response.Write "The transaction was committed and your order is being sent."
End Sub
Output:
The transaction was committed and your order is being sent.