populating insert query with data from 2D array in Coldfusion

eblanke
eblanke used Ask the Experts™
on
Hi All,

I'm trying to insert the contents of a 2D array into a database. I'm having a hell of a time getting it to work. Below is what I've tried, but it gives an error (The value coldfusion.runtime.Array cannot be converted to a number.). What should I be doing?

<cfloop array="#measureValues#" index="i" >
        <cfquery name="updateAss_DRDP_line" datasource="#application.dsn#" username="#application.username#" password="#application.password#" > 
INSERT INTO CDP_Ass_DRDP_line ( AssessmentID, MeasureID , Value1, Value2, Value3, Value4, Value5, Value6, UnableToRate,  ) VALUES ( <cfqueryparam cfsqltype="cf_sql_int" value="#attributes.AssessmentID#" /> , 
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][8]#" /> , 
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][1]#" /> , 
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][2]#" /> ,
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][3]#" /> ,
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][4]#" /> ,
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][5]#" /> ,
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][6]#" /> ,
<cfqueryparam cfsqltype="cf_sql_integer" value="#measureValues[i][7]#" /> ) 
</cfquery>
      </cfloop>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Commented:
>> <cfloop array="#measureValues#" index="i" >

I think you're confusing a from/to loop with an array loop. With an array loop, the variable #i# is an element of the array, not a simple number.  cfdump it to see what it contains.  

Instead of
.... value="#measureValues[i][8]#"

You probably want something more like:
....  value="#i[8]#"

Author

Commented:
Excellent! that worked :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial