p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_databases thread: Return identity , cancel update further down in code


Message #1 by dont worry <aspmailbox@y...> on Thu, 6 Dec 2001 07:40:03 -0800 (PST)
I open connection, create recordset, add some records,

rs.update and return auto/number (identity) in access.

 I need the value to build subquerys, but if error

arises further down in code, I need to rs.cancelBatch

or rs.cancelUpdate.



PROBLEM is that I need identity,(no problem getting

identity), to build subqueries and I need to be able

to cancel the update (where I got the identity) if an

error arises further down in my code. 

(Note I tried moving the rs.Update to the if statment,

but then it will not return the identity upfront like

I need.)(Baically, i need the identity now and finish

the update later.) - Should and how do I turn this

into a cn.begin trans....



My code is below.



SET RS = server.createobject("adodb.recordset")

RS.Open "USERS", cn, adOpenKeySet,  adLockOptimistic,

adCmdTable



RS.AddNew

RS("FIRST_NAME") = FIRST_NAME

RS("LAST_NAME") = LAST_NAME

RS("SOCIAL_SECURITY") = SOCIAL_SECURITY

RS("CREATEDBY") = "WEBFORM"

RS("CREATEDDTM") = DATE()

RS.Update

MYID = RS("USER_ID")

Response.Write MYID &" =ID"





'further down

If error_count =0 then

  continue

else

  rs.CancelUpdate

end if



__________________________________________________

Do You Yahoo!?

Send your FREE holiday greetings online!

http://greetings.yahoo.com

Message #2 by dont worry <aspmailbox@y...> on Thu, 6 Dec 2001 17:55:40 -0800 (PST)
Use 

cn.beginTrans



cn.RollbackTrans



cn.CommitTrans

Thanks!



--- dont worry <aspmailbox@y...> wrote:

> I open connection, create recordset, add some

> records,

> rs.update and return auto/number (identity) in

> access.

>  I need the value to build subquerys, but if error

> arises further down in code, I need to

> rs.cancelBatch

> or rs.cancelUpdate.

> 

> PROBLEM is that I need identity,(no problem getting

> identity), to build subqueries and I need to be able

> to cancel the update (where I got the identity) if

> an

> error arises further down in my code. 

> (Note I tried moving the rs.Update to the if

> statment,

> but then it will not return the identity upfront

> like

> I need.)(Baically, i need the identity now and

> finish

> the update later.) - Should and how do I turn this

> into a cn.begin trans....

> 

> My code is below.

> 

> SET RS = server.createobject("adodb.recordset")

> RS.Open "USERS", cn, adOpenKeySet, 

> adLockOptimistic,

> adCmdTable

> 

> RS.AddNew

> RS("FIRST_NAME") = FIRST_NAME

> RS("LAST_NAME") = LAST_NAME

> RS("SOCIAL_SECURITY") = SOCIAL_SECURITY

> RS("CREATEDBY") = "WEBFORM"

> RS("CREATEDDTM") = DATE()

> RS.Update

> MYID = RS("USER_ID")

> Response.Write MYID &" =ID"

> 

> 

> 'further down

> If error_count =0 then

>   continue

> else

>   rs.CancelUpdate

> end if

> 

> __________________________________________________

> Do You Yahoo!?

> Send your FREE holiday greetings online!

> http://greetings.yahoo.com

> 

>  



> aspmailbox@y...


> $subst('Email.Unsub')

> 





$subst('Email.Unsub').





__________________________________________________

Do You Yahoo!?

Send your FREE holiday greetings online!

http://greetings.yahoo.com


  Return to Index