Hi Dave,

Thanks for that.  I’ll stick with the simple stuff until I get a bit
better at this stuff.  I’ve put in the necessary code but I’m getting a
"Element PROPERTYAGENTID is undefined in GETUSERID." Error.

Can you see what I'm doing wrong?

<cftransaction action="">   
<CFQUERY NAME="InsertPropertyDetails" datasource="020">
INSERT INTO PropertyAgent
(PropertyAgentCompanyName, PropertyAgentFlatNumberHouseName,
PropertyAgentStreetNumber, PropertyAgentStreetName,
PropertyAgentVillageTown, PropertyAgentCountyState,
PropertyAgentPostcodeZip, PropertyAgentCountry,
PropertyAgentTelephoneNumber, PropertyAgentContactFirstName,
PropertyAgentContactSurname, PropertyAgentContactMobile,
PropertyAgentEmailAddress, PropertyAgentAuthorityLevel,
PropertyAgentDateAdded, PropertyAgentViewDefinitions,
PropertyAgentCreatedBy)
VALUES
('#Form.PropertyAgentCompanyName#',
'#Form.PropertyAgentFlatNumberHouseName#',
#Form.PropertyAgentStreetNumber#, '#Form.PropertyAgentStreetName#',
'#Form.PropertyAgentVillageTown#', '#Form.PropertyAgentCountyState#',
'#Form.PropertyAgentPostcodeZip#', '#Form.PropertyAgentCountry#',
#Form.PropertyAgentTelephoneNumber#,
'#Form.PropertyAgentContactFirstName#',
'#Form.PropertyAgentContactSurname#', #Form.PropertyAgentContactMobile#,
'#Form.PropertyAgentEmailAddress#', #Form.PropertyAgentAuthorityLevel#,
#UKDate#, '#GetDefaultViewDefinitions.ViewDefinitions#',
#Client.PropertyAgentID#)
</CFQUERY>

<CFQUERY NAME="GetUserID" datasource="020">
SELECT MAX(PropertyAgentID)
FROM
PropertyAgent
</CFQUERY>
  
<cfoutput>#GetUserID.PropertyAgentID#</cfoutput>

</cftransaction>

Thanks,

Stuart

-----Original Message-----
From: Dave Carabetta [mailto:[EMAIL PROTECTED]
Sent: 01 February 2004 15:27
To: CF-Talk
Subject: Re: CFLOCK:....Sunday (still not left computer all weekend,
flatmates will start thinking i have problems)

> Hi guys,
>
> I'm inserting a record to a database, but once I have inserted the
> record I want to email the user their details including their UserID
> which is an autonumber (primary).
>
> To grab the last inserted row should I use the CFLOCK around my query
> and my cfmail?  Is there such a thing as Last.UserID which will give
me
> the last insert of UserID?
>

No, cftransaction is what you want to use. One way to solve your problem
would be:

<cftransaction action="">   <cfquery ....>
  INSERT ....
  </cfquery>

  <cfquery ....>
  SELECT MAX(id)
  FROM foo
  </cfquery>
</cftransaction>

However there are also other "more elegant" ways of solving this problem
as
well. You could write a stored proc that does the insert and returns the
value for you. Also, and I could be wrong on this, I *think* that JDBC
has a
way of returning the row id just inserted, so you may want to look in to
that as well. Again, I could be way off on that, but I could swear I
read
that somewhere.

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to