Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid column number when updating my record 1

Status
Not open for further replies.

Fleer

Programmer
Mar 8, 2001
11
BE
Hi Guys,

I've created a dynamic form and I added a submit button to save the updated data. I've used <CFUPDATE> because I don't know wich fields will be in the form (this is based on certain chooses the user makes).

<cfupdate datasource=&quot;Myconnection&quot; tablename=&quot;DBname&quot; formfields=&quot;#FORM.Fieldnames#&quot;>

I also included my primary key as a hidden field in my form.

Now I get the error saying : Error Executing Database Query
Invalid column number. (I'm using a Visual Foxpro database)

I've been looking at this problem for some hours now and I hope someone can help me

TIA
Fleer
 
Are your form field names and database column names the same? I've not used cfupdate much, but I think the names have to be the same.

You could probably use sql. This is off the top of my head, and could probably be written a little neater (maybe using cfloop to loop over your fieldnames), but might point you in the right direction:

<cfset variables.string = &quot;&quot;>

<cfif isDefined(&quot;form.field_1&quot;)>
<cfset variables.temp = &quot;column_1 = 'field_1'&quot;>
<cfset variables.string = listAppend(variables.string, variables.temp, &quot;,&quot;)>
</cfif>

<cfif isDefined(&quot;form.field_2&quot;)>
<cfset variables.temp = &quot;column_2 = 'field_2'&quot;>
<cfset variables.string = listAppend(variables.string, variables.temp, &quot;,&quot;)>
</cfif>

<cfquery datasource=&quot;myDSN&quot;>
update myTable
set #variables.string#
where id = #form.id#
</cfquery>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top