Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error 500 when comparing recordset results

Posted on 2004-04-22
6
Medium Priority
?
298 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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