Solved

Error 500 when comparing recordset results

Posted on 2004-04-22
6
279 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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