Solved

Error 500 when comparing recordset results

Posted on 2004-04-22
6
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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