Forum Moderators: open

Message Too Old, No Replies

ASP101.com Database Sample

         

charonlee

11:31 am on Apr 30, 2003 (gmt 0)

10+ Year Member



In ASP101 database sample (add/delete/update), I found that it likes to use ADO native method , means that recordset instead of Connection object with SQL command (conn.execute(SQL)).

Doesn't the Connection object provides more good performance than recordset? and more easier
to be implemented. For instance, I want to make a bank transaction, creadit one account and debit one accout as below:

account A transfer to account B

By Using connection object.
BeginTrans
con.execute("Update customer Set balance = balance - amount Where CusNo = 20")
con.execute("Update customer Set balance = balance + amount Where CusNo = 21")
CommitTrans / rollbackTrans if error

We can use transaction at this level, more stable and secure.

if we use recordset, we need to create two recordset:

sQL = "Select balance from customer where CusNo = 20"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open sQL, con
objRS("balance") = objRS("balance") - amount
objRS.Update
Response.Write ("Record Updated")

sQL2 = "Select balance from customer where CusNo = 21"
Set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open sQL, con
objRS2("balance") = objRS("balance") - amount
objRS2.Update
Response.Write ("Record Updated")

What will happen if the first transaction is not succeed? Can the recordset batchupdate be used to replace the transaction?

Xoc

5:41 am on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



*bump*