I use cftransaction to lock the database and ensure that both inserts
happen, or nothing at all happens.....what follows is pretty much right
out of docs online, but for what it's worth, here you go:

<CFtransaction action="begin">
<cftry>
        <cfquery datasource="#request.dsn#" name="firstInsert" dbtype="ODBC">
                insert into myUserTable
                (username)
                values 
                ( <cfqueryparam value="#form.username#" 
cfsqltype="CF_SQL_VARCHAR"
maxlength="10">)
        </cfquery>
                
        <cfquery datasource="#dsn#" name="GetNewID" dbtype="ODBC">
                SELECT @@identity as newid from myUserTable
        </cfquery>
                
        <cfset id=GetNewID.newid>
        <cfset today=CreateODBCDateTime(now())> 

        <cfquery datasource="#dsn#" name="secondInsert" dbtype="ODBC">
                insert into myOtherTable
                (theNewID, theDate)
                values 
                ( <cfqueryparam value="#id#" cfsqltype="CF_SQL_INTEGER">, 
#today#)
        </cfquery>

   <cfcatch type ="any">
        Some error trapping of your choice should go here.
    </cfcatch>
</cftry>
</CFTRANSACTION>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2188
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to