VB icon

ADO Transactions

Email
Submitted on: 1/1/2015 12:20:00 AM
By: Found on the World Wide Web (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 917
 
     Transactions are atomic operations that allow you to do multiple operations on a database as one operation. For example, if you were creating a banking application in which you deducted $100 from one account and added it to another account, you wouldn't want the operation to fail right in the middle, because the money would be 'lost'! The solution is to wrap the SQL in a transaction. If the operation is aborted in the middle (the pc gets shut off for example) the database will rollback the changes so that the initial account was never debited the $100. This will make you feel good, especially if its your bank account!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ADO Transactions
' Description:Transactions are atomic operations that allow you to do multiple operations on a database as one operation. For example, if you were creating a banking application in which you deducted $100 from one account and added it to another account, you wouldn't want the operation to fail right in the middle, because the money would be 'lost'! The solution is to wrap the SQL in a transaction. If the operation is aborted in the middle (the pc gets shut off for example) the database will rollback the changes so that the initial account was never debited the $100. This will make you feel good, especially if its your bank account!
' By: Found on the World Wide Web (from psc cd)
'**************************************

<% Response.Expires = 0 %>
<HTML>
<HEAD><TITLE><H3>Transactions</H3></TITLE></HEAD>
<BODY BGColor=ffffff Text=000000>
<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open Application("guestDSN")
Set rs = Server.CreateObject("ADODB.RecordSet")
MySQL = "SELECT * FROM paulen"
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.ActiveConnection = cn
rs.Source = MySQL 
rs.Open 
%>
<h2>Before:<BR>
<TABLE BORDER=1>
<TR>
<% For i = 0 to RS.Fields.Count - 1 %>
<TD><B><% = RS(i).Name %></B></TD>
<% Next %>
</TR>
<% Do While Not RS.EOF %>
<TR>
<% For i = 0 to RS.Fields.Count - 1 %>
<TD VALIGN=TOP><% = RS(i) %></TD>
<% Next %>
</TR>
<%
RS.MoveNext
Loop
RS.Close
%>
</TABLE>
<%
cn.BeginTrans
cn.Execute("INSERT INTO paulen (fld1, fld2) VALUES ('Aborted', 50)")
cn.RollbackTrans
cn.BeginTrans
cn.Execute("INSERT INTO paulen (fld1, fld2) VALUES ('Trans" & Time() & "', 100)")
cn.CommitTrans
%>
Completed.<P>
<h2>After:</h2>
<TABLE BORDER=1>
<TR>
<% 
rs.Open 
For i = 0 to RS.Fields.Count - 1 %>
<TD><B><% = RS(i).Name %></B></TD>
<% Next %>
</TR>
<% Do While Not RS.EOF %>
<TR>
<% For i = 0 to RS.Fields.Count - 1 %>
<TD VALIGN=TOP><% = RS(i) %></TD>
<% Next %>
</TR>
<%
RS.MoveNext
Loop
RS.Close
Cn.Close
%>
</TABLE>


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.