Solved

Error 500 when comparing recordset results

Posted on 2004-04-22
6
281 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update field in order 21 143
Auto Submit on dropdown box 14 66
Connecting to multiple databases to create a Dashboard 5 26
alert(innerHTML); 8 19
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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