Solved

Error 500 when comparing recordset results

Posted on 2004-04-22
6
278 Views
Last Modified: 2006-11-17
I'm having trouble with my asp script to build a menu.  I'm using an Access database.  My script *should build a menu by looping through categories in my database.  The problem occurs when I try to compare records between recordsets.  I'm trying to make the text bold if for the category currently being viewed.  I've tried making both results into variables and then comparing the variables, and I get the same error 500.  If I take the comparison out of my script, the script runs fine, just without the current category being hilighted.

<%
'get a list of all categories
dim CatList
set CatList = server.createobject("ADODB.recordset")
set CatList = conlayout.execute("SELECT idCategory, categoryDesc FROM categories WHERE idRootCategory = 1 ORDER BY idCategory")

'get the current category being viewed
dim MenuCategory
MenuCategory = request("idCategory")

'get info about the current category
dim MenuRoot
set MenuRoot = server.createobject("ADODB.recordset")
set MenuRoot = conlayout.execute("SELECT * FROM categories WHERE idCategory = '"&MenuCategory&"'")

'declare and set IsBold variable
      dim IsBold
      IsBold = "normal"

do while not CatList.EOF
      'reset IsBold for each loop
      IsBold = "normal"
'if the current CatList record is the same as the current category's root category, then make the text bold
if MenuRoot("idRootCategory") = CatList("idCategory") then IsBold = "bold"
%>
   <tr>
      <td style="font-weight:<% =IsBold%>;">
         <% =CatList("categorydesc")%>
      </td>
   </tr>
<%
CatList.MoveNext
loop
%>

I can't figure out what I'm doing wrong here, it should be working just fine.  I need some expert advice here guys.

Thanks in advance

-Jared
0
Comment
Question by:YbNormalMan
  • 4
  • 2
6 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 10890686
This is wrong:

set CatList = server.createobject("ADODB.recordset")
set CatList = conlayout.execute("SELECT idCategory, categoryDesc FROM categories WHERE

Only need to set once: this is correct way to do it...

set CatList = server.createobject("ADODB.recordset")
SQL = "SELECT idCategory, categoryDesc FROM categories WHERE idRootCategory = 1 ORDER BY idCategory"

CatList.Open SQL, conlayout, 2, 3


Then to compare do this:

MenuCategory = request("idCategory")

do while not CatList.EOF
     'reset IsBold for each loop
     IsBold = "normal"
'if the current CatList record is the same as the current category's root category, then make the text bold
if MenuCategory = CatList("idCategory") then
 IsBold = "bold"
 %>
   <tr>
      <td style="font-weight:<% =IsBold%>;">
         <% =CatList("categorydesc")%>
      </td>
   </tr>
<%
else
  IsBold = "normal"
end if
CatList.MoveNext
loop
%>
0
 
LVL 1

Author Comment

by:YbNormalMan
ID: 10890884
Changing the method of opening the recordset didn't help.  The problem seems to occur when I try to compare the result of one recordset with another.  The MenuRoot recordset gets the root category of the page being viewed, and the CatList recordset is the set being looped through.  When I try to compare to see if the CatList category is the same as the MenuRoot root category, that's when I get the problem.  They're both integer data types.

**correction from my original post:  the database is a MS SQL database
0
 
LVL 31

Expert Comment

by:alorentz
ID: 10890911
I also gave you the appropriate comparison code....not just the recordset stuff!
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:alorentz
ID: 10890928
Try this:  copy and paste all code here

MenuCategory = request("idCategory")
dim catid
do while not CatList.EOF
     'reset IsBold for each loop
     IsBold = "normal"
'if the current CatList record is the same as the current category's root category, then make the text bold
catid = CatList("idCategory")
if MenuCategory = catid then
 IsBold = "bold"
 %>
   <tr>
      <td style="font-weight:<%=IsBold%>;">
         <% =CatList("categorydesc")%>
      </td>
   </tr>
<%
else
  IsBold = "normal"
end if
CatList.MoveNext
loop
%>
0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 10890947
If that doesn't work, then there is no value in request("idCategory") that macthes the values in the DB...then try this to see what is being passed:

Response.Write "CATEGORY being passed:" & request("idCategory")
Response.end

0
 
LVL 1

Author Comment

by:YbNormalMan
ID: 10891028
That was the problem -- the first record of the recordset returned by MenuRoot was a null value which couldn't be compared.  Thanks for the quick help alorentz!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now