|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
check if recordset exists?
how do i check if a recordset exists? i can't use isDefined() that wont work for queries. can't user .recordcount or len() because they assume and the recordset exists in the first place. any ideas?
|
|
#2
|
|||
|
|||
|
<cfif queryName.recordCount gt 0>
record set exists </cfif> |
|
#3
|
|||
|
|||
|
isDefined() will certainly work on a query name. You can also do:
<cfif structKeyExists( variables, 'myQueryName' )> (assuming the query is in the variables scope of course).
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#4
|
|||
|
|||
|
but isDefined() did NOT work, i got an error saying isDefined() will not work on complex variables, such as a recordset. and again, .recordcount did NOT work because that assumes the recordset exists in the first place. if the recordset does not exist it'll blow up saying ".recordcount is not defined in variable [insert name here]" or something along those lines
|
|
#5
|
|||
|
|||
|
You might try being a bit less emphatic, because I am telling you that you are doing something wrong. I think what you mean is "I can't make it work" or "It's not working for me". This code works fine and both conditions are met.
Code:
<cfquery name="qryGetCatalog" datasource="wegotwidgets">
select productID,
productName,
productDescription,
imageFile,
price
from Products
order by productName
</cfquery>
<cfif isDefined( 'qryGetCatalog' )>
its defined
</cfif>
<br><br>
<cfif structKeyExists( variables, 'qryGetCatalog' )>
the struct key exists
</cfif>
I recommend using structKeyExists() instead of isDefined() because it is more specific (it's forcing a lookup in only the variables scope, while isDefined() will automatically look for the variable in any of the auto-lookup scopes beyond the variables scope). Last edited by kiteless : March 3rd, 2005 at 09:54 AM. |
|
#6
|
|||
|
|||
|
oh ok i see... thanks!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > check if recordset exists? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|