Skip to main content
jbird5k
Inspiring
March 25, 2008
Answered

queries inside cfc's

  • March 25, 2008
  • 4 replies
  • 756 views
I am having an issue with using a query inside a component:

I am passing two variables to a component; user name and password, the query returns the username, useraccess and staff id. When I invoke the component I want to check for a record and allow or deny access acordingly.

my issues, I am being forced to use a returntype of string or any. it won't take query.

I get an error everytime I try to use recordcount. Recordcount is not defined in...


<cfcomponent>
<cffunction name="mylogin" access="public" returntype="string" >
<cfargument name="UserName" type="string" required="yes">
<cfargument name="Password" type="string" required="yes">

<cfset var login="">

<cfquery datasource="TimeReporting" name="login" result="result">
SELECT UserName,UserPassword,UserAccess,staffID
FROM tblStaff WHERE UserName='#Arguments.UserName#'
AND UserPassword='#Arguments.Password#'
</cfquery>

<cfreturn mylogin>
</cffunction>
</cfcomponent>



here is the error message:

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Element RECORDCOUNT is undefined in MYLOGINRET.

ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.
Resources:

* Check the ColdFusion documentation to verify that you are using the correct syntax.
* Search the Knowledge Base to find a solution to your problem.

Browser Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
Remote Address ::1
Referrer http://localhost/jays_dev/TMR/login.cfm
Date/Time 25-Mar-08 03:57 PM
Stack Trace
at cfaccess2d12ecfm319416303.runPage(C:\inetpub\wwwroot\jays_dev\TMR\access-1.cfm:44)
This topic has been closed for replies.
Correct answer jbird5k
Thank you,

I haven't written very many cfc's and was under the impression that I had to return the function name. It does make sense to return the query name.

4 replies

Inspiring
March 26, 2008
jbird5k,

Btw, you forgot to "var" scope the result name.

<cfset var login="">
<cfset var result="">
<cfquery datasource="TimeReporting" name="login" result="result">
...

Though if you are not using "result", you could also remove it entirely.
Participating Frequently
March 26, 2008
<cfset var login="">
<cfset var myrecordcount="">

<cfquery name="login ...

</cfquery>

<cfset myrecordcount= login.recordcount>

<cfreturn myrecordcount>
Astonished_protector15C3
Participating Frequently
March 26, 2008
Hi

In your query you are returning the variable name is the function name <cfreturn mylogin>

If you want to get the recordcount you have to return the queryname

Replace your <cfreturn mylogin> with <cfreturn login>

Hope you understand your mistake
jbird5k
jbird5kAuthorCorrect answer
Inspiring
March 26, 2008
Thank you,

I haven't written very many cfc's and was under the impression that I had to return the function name. It does make sense to return the query name.
Inspiring
March 25, 2008
jbird5k wrote:
> <cfset var login="">

> <cfquery datasource="TimeReporting" name="login" result="result">

> <cfreturn mylogin>

If you look closely at these three lines of code you will probably see
the problem.

If not, it is not 'my' problem.

HTH
Ian