Link to home
Start Free TrialLog in
Avatar of cfsatx
cfsatx

asked on

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

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

Avatar of _agx_
_agx_
Flag of United States of America image

> <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..

Avatar of cfsatx
cfsatx

ASKER

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

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
Avatar of cfsatx

ASKER

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
Avatar of cfsatx

ASKER

How can I get rid of the bind error ?
> 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()"




Avatar of cfsatx

ASKER

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"



ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cfsatx

ASKER

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.,