We help IT Professionals succeed at work.

Bind value is not a 2D array or valid serialized query

cfsatx
cfsatx asked
on
If I use cfinvoke, I am able to see the country code. But if I use CFSELECT with a bind, I get the bind value error. Please help. Thanks
dmis.cfc

<cfcomponent displayname="dmis" output="no">
 <cffunction name="getCountry" hint="Gets all country codes from the database" returntype="query" access="remote">
    <cfset var countrydata="">
    <cfquery datasource="#TIMPOLookupDSN#" name="countrydata">
	 SELECT distinct Facility_Country_Code
	 FROM DMIS
     where Facility_Country_Code is not null
	 ORDER BY Facility_Country_Code
   </cfquery>
   <cfreturn valueList(countrydata.Facility_Country_Code)>
 </cffunction>
</cfcomponent>

test.cfm

<cfform>
<TR>
<TD align="right" nowrap>Country:</TD>

<TD>
<cfselect name="countrycode" bind="BBoard.cfc:dmis.getCountry()" bindonload="true" value="countrycode" />
</TD>
</TR>
</cform>

Open in new window

Comment
Watch Question

Most Valuable Expert 2015

Commented:
> <cffunction name="getCountry" returntype="query"

The function says it returns a query but returns a string instead.  If you're using CF8.01 or higher, just return the whole query object.

      <cfreturn countrydata>
 </cffunction>

.. and use the query column name in your cfselect

<cfselect name="countrycode"
       bind="BBoard.cfc:dmis.getCountry()" bindonload="true"
      display="Facility_Country_Code"
      value="Facility_Country_Code" />
You're returning a comma delimited list of values from your cfc, you should return either an array or a query... try just returning countrydata

but also, a select requires two values, the Value and the Display.   If DMIS has a primary key you should return that for the value...  and the name of the country as the display.. that's two columns..

Author

Commented:
I am using CF9...I changed my dmis.cfc and test.cfm just the same way you said. I still get the bind error. Thanks for your help.
dmis.cfc

<cfcomponent displayname="dmis" output="no">
 <cffunction name="getCountry" hint="Gets all country codes from the database" returntype="query" access="remote">
   <cfargument name="TIMPOLookupDSN" type="string" required="yes" default="TIMPO_Lookup_Dev_RW">
    <cfset var countrydata="">
    <cfquery datasource="#TIMPOLookupDSN#" name="countrydata">
	 SELECT distinct Facility_Country_Code
	 FROM DMIS
     where Facility_Country_Code is not null
	 ORDER BY Facility_Country_Code
   </cfquery>
   <cfreturn countrydata>
 </cffunction>
</cfcomponent>


test.cfm
<cfform>
<TR>
<TD align="right" nowrap>Country:</TD>
<TD>
<cfselect name="countrycode" 
       bind="BBoard.cfc:dmis.getCountry()" bindonload="true" 
      display="Facility_Country_Code" 
      value="Facility_Country_Code" />

</TD>
</TR>
</cfform>

Open in new window

Most Valuable Expert 2015

Commented:
What's the error?  Also, what are the results if you call the function directly

ie   http://yoursite.com/path/to/dmis/getCountry.cfc?method=getCountry

Author

Commented:
This is the error I am getting when I use CFSELECT bind

error:bind: Bind failed for select box countrycode,
bind value is not a 2D array or valid serialized query


I get country codes correctly when I call the function directly
mysite/dmis.cfc?method=getCountry

Author

Commented:
How can I get rid of the bind error ?
Most Valuable Expert 2015

Commented:
> bind="BBoard.cfc:dmis.getCountry()"

Just noticed the syntax for your bind is wrong. It should be:

        bind="cfc:path.to.YourComponent.methodName()

So if your component is named "dmis.cfc" and is directly beneath the web root:

        bind="cfc:dmis.getCountry()"




Author

Commented:
I get CFC function not found in the bind expression

when I use  bind="cfc:path.to.YourComponent.methodName()"

My .cfm and ,cfc are in the same folder

I use like this
bind="cfc:https://#cgi.SERVER_NAME#/TIMPODash/BBoard/dmis.cfc?method=getCountry"



Most Valuable Expert 2015
Commented:
> when I use  bind="cfc:path.to.YourComponent.methodName()"

That was just an example illustrate what path is needed.  Use the example below it

ie     bind="cfc:dmis.getCountry()"

Author

Commented:
This worked. Thanks for your help.

<cfselect name="countrycode"
      bind="cfc:dmis.getCountry()" bindonload="true"
      display="Facility_Country_Code"
      value="Facility_Country_Code" />

I am working on depending drop downs. Do you have any example? Selecting Country code should populate all states and selecting a state should populate all cities with in that...etc.,