469,295 Members | 1,953 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,295 developers. It's quick & easy.

A simple code comparing querystring to recordset value

Hi

I am desperate for some help. I have a very simple piece of code that doesn't work.

I request a number from the query string
I request a number from a database (MS Access)

If one is bigger, display true, else, display false!!

Then, go to the next item and do the same until EOF/BOF

So, my code looks like
Expand|Select|Wrap|Line Numbers
  1. While ((RepeatAdvancedSearchResults__numRows <> 0) AND (NOT rsAdvancedSearchResults.EOF)) 
  2.  
  3.  
  4. if (rsAdvancedSearchResults.Fields.Item("MinContacts").Value) >= request.QueryString("contacts") then
  5. response.write("It worked")
  6. else
  7. response.write("It did NOT work")
  8. end if
  9. %>
  10.  
  11. SHOW INFORMATION
  12.  
  13. <% 
  14.   RepeatAdvancedSearchResults__index=RepeatAdvancedSearchResults__index+1
  15.   RepeatAdvancedSearchResults__numRows=RepeatAdvancedSearchResults__numRows-1
  16.   rsAdvancedSearchResults.MoveNext()
  17. Wend
  18. %>
The page loads as it should do, but it doesn't do the maths. Either every product is true, or every product is false.

I have tried converting the numbers into variables. Do I need to tell the computer the variable is an int??


Please help

Thanks

Dave
Oct 10 '07 #1
2 1649
The answer (I would normally remove the link/post, but I don't know how to, so instead of leaving it, I thought I would answer it)

Define the conditions with the SQL. So, I wrote

rsAdvancedSearchResults.Source = "SELECT * FROM GradParts where ((MinContacts <= " + replace (var_Contacts,"'","''") + ") and (MaxContacts >= " + replace (var_Contacts,"'","''") + "))

At first, it still wouldn't work.During the replace code, it is normally started with '" (please note the single quotation mark) which make it a string. Removing it made it an int!! (I think)

Dave
Oct 10 '07 #2
jhardman
3,406 Expert 2GB
At first, it still wouldn't work.During the replace code, it is normally started with '" (please note the single quotation mark) which make it a string. Removing it made it an int!! (I think)
Yes, that is how you show the difference tin SQL. unfortunately, VBScript doesn't work so well, and it is always assumed that anything sent via querystring is a string. Your first code could be adapted like this:
Expand|Select|Wrap|Line Numbers
  1. dim myNum
  2. myNum = cint(request.querystring("contacts"))
  3. if (rsAdvancedSearchResults.Fields.Item("MinContacts").Value) >= myNum then
the cint() function converts a string to an integer, then this value can be used for the comparison.

Jared
Oct 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Samantha Smit | last post: by
reply views Thread by collie | last post: by
73 posts views Thread by Claudio Grondi | last post: by
1 post views Thread by RN1 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.