This is becoming kind of tricky. I want to output the primary key of the record I just inserted. I am doing an insert of multiple records:
My insert statement looks something like this:
<cfquery name="imprtFiles" datasource="#mydsn#" result="#result#">
<cfoutput query="myFileList">
INSERT INTO myTablename (mycolumn) VALUES ('#valuegohere#');
</cfoutput>
</cfquery>
<cfset newID = result.IdentityCol>
<cfoutput>#newID#</cfoutput>
And this throws a CF Error:
"Element IDENTITYCOL is undefined in RESULT."
So I'm thinking that there is hopefully another way to get PK of the record I just inserted. Any thoughts?
Here is the code I used according to the example:
<cftransaction>
<cfquery name="importFiles" datasource="#dsn#" result="result">
<cfoutput query="myFileList">
INSERT INTO tbl_logfiles (originalFile, originalFileSize) VALUES ('#name#', '#length#');
</cfoutput>
</cfquery>
<cfquery name="getID" datasource="#dsn#">
select Max(fileID) as NewID from tbl_logfiles;
</cfquery>
</cftransaction>
<cfset newID = getID.NewID>
<cfoutput> #newID# </cfoutput>
The output I get from #newID#
is 280, which is the highest fileID in my database table at this time. Weird.
What I am trying to get is the last whatever N
records I imported. I was hoping there was a way I could output it somehow from the cfoutput
tag based on the cfquery.result
.