macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

Re: Display fields on Action Page

Subject: Re: Display fields on Action Page
From: "Avatar"
Date: Fri, 17 Aug 2007 18:28:17 +0000 UTC
Newsgroups: macromedia.coldfusion.cfml_general_discussion
First, I would not be using ParameterExists as this function has been 
deprecated since CF 6 I believe and might not work in later releases, use 
IsDefined("Add") instead.

 Now on to your question, you cannot insert any values into fields such as 
autonumber or "auto identity" fields, the database inserts these values 
themselves when a new record is created.

 For this purpose I would not use <cfinsert, instead use <cfquery to insert 
into your database.

 <cflock timeout="30" throwontimeout="yes" 
name="InsertIntoConf2007Registration" type="EXCLUSIVE">

 <cftransaction>
 <cfquery name="Insert" datasource="DSSurvey">
 INSERT INTO Conf2007Registration (Name, Email, County, Title, Phone, Address1, 
Address2, PO, CityStateZip, Guests, Golfyes, Company, Allergies, Vegie2, 
Social, Comments)
 VALUES ('#form.Name#', '#form.Email#', '#form.County#', '#form.Title#', 
'#form.Phone#', '#form.Address1#', '#form.Address2#', '#form.PO#', 
'#form.CityStateZip#', '#form.Guests#', '#form.Golfyes#', '#form.Company#', 
'#form.Allergies#', '#form.Vegie2#', '#form.Social#', '#form.Comments#')
 </cfquery>

 <!--- @@identity is a built-in variable that holds only the most recent 
autonumber or auto identity value from a table, for this reason we wrap the 
entire section in a cflock so that we do not run into "race conditions" where 2 
users could get the same value or swap values. Once an insert starts everyone 
else has to wait until the lock is finished so you guarantee that the newly 
inserted autonumber is actually correct for that insert --->
 <cfquery name="GetNewID" datasource="DSSurvey">
 SELECT         @@identity AS TheNewlyInsertedID
 FROM   Conf2007Registration
 </cfquery>

 <cfoutput> 
 Your registration number is #GetNewID.TheNewlyInsertedID#
 </cfoutput>

 </cftransaction>
 </cflock>


<Prev in Thread] Current Thread [Next in Thread>