"If valueDB = valueQS then" statement not working

  • Thread starter Aaron [SQL Server MVP]
  • Start date
A

Aaron [SQL Server MVP]

You might try comparing apples to apples, e.g. if clng(something) =
clng(something_else) then

--
http://www.aspfaq.com/
(Reverse address to reply.)




Chris Tilley - HPC:Factor said:
Hi,

I'm utterly confounded by this one. There must be some sort of rule that
I don't know of. I'd consider myself a Newbie+1, so be gentle.

I have a database connection (working A-Ok) and a Query String value from a
form (passed using GET & working Ok). The server is IIS5.

What I'm trying to do is get a simple IF statement to work accross the two
numeric values. Once from a database and one from a Query String.

If %Database value% = %query string value% then
response.write("something")
else
response.write("nothing")
end if

...but it's not working. It always without fail responds with "nothing".
If I response.write the database variable and the query strings the values
are all numeric and there is always going to be a match. There are only 3
records in the database and 3 options on the form.

If I change it to %Database value%=%Database value% then it works,
specifying "something" on all the results. If I manually place a numeric
value into the code in place of %Query string value% it works as it should
do, except that of course it's static.

Here is the entire code segment:

<%
checkmcat=Request.Querystring("mstrcat")
SQLREVMCAT="SELECT TBL_revmcat.revmcat_ID, TBL_revmcat.revmcat_Name FROM
TBL_revmcat ORDER BY TBL_revmcat.revmcat_Name"
set revmcat = server.createobject("ADODB.Connection")
revmcat.open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/database.mdb")
set REV_mcat=revmcat.execute(SQLREVMCAT)
%>

<% do while not REV_mcat.eof %>
<option<% if REV_mcat(0) = checkmcat then
response.write(" SELECTED")
else
response.write("")
end if %> value="<%= REV_mcat(0) %>">- <%= REV_mcat(1)
%> said:
<%REV_mcat.movenext
loop%>
<% revmcat.close %>
</select>

revmcat_ID [ REV_mcat(0) ] is a long integer AutoNumber in the Access 2000
database & is the tables Primary Key.
I've come across this before on another project I was fiddling with, in the
end I just completly change the entire database / code to work around the
problem. I can't see away round it this time though.

I guess that it is probably something obvious, or a rule I don't know of.
I've just been staring at it for so long, I'm suffering code blindness.

Thanks.

Chris
 
C

Chris Tilley - HPC:Factor

Hi,

I'm utterly confounded by this one. There must be some sort of rule that
I don't know of. I'd consider myself a Newbie+1, so be gentle.

I have a database connection (working A-Ok) and a Query String value from a
form (passed using GET & working Ok). The server is IIS5.

What I'm trying to do is get a simple IF statement to work accross the two
numeric values. Once from a database and one from a Query String.

If %Database value% = %query string value% then
response.write("something")
else
response.write("nothing")
end if

....but it's not working. It always without fail responds with "nothing".
If I response.write the database variable and the query strings the values
are all numeric and there is always going to be a match. There are only 3
records in the database and 3 options on the form.

If I change it to %Database value%=%Database value% then it works,
specifying "something" on all the results. If I manually place a numeric
value into the code in place of %Query string value% it works as it should
do, except that of course it's static.

Here is the entire code segment:

<%
checkmcat=Request.Querystring("mstrcat")
SQLREVMCAT="SELECT TBL_revmcat.revmcat_ID, TBL_revmcat.revmcat_Name FROM
TBL_revmcat ORDER BY TBL_revmcat.revmcat_Name"
set revmcat = server.createobject("ADODB.Connection")
revmcat.open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/database.mdb")
set REV_mcat=revmcat.execute(SQLREVMCAT)
%>

<% do while not REV_mcat.eof %>
<option<% if REV_mcat(0) = checkmcat then
response.write(" SELECTED")
else
response.write("")
end if %> value="<%= REV_mcat(0) %>">- <%= REV_mcat(1) %></option>
<%REV_mcat.movenext
loop%>
<% revmcat.close %>
</select>

revmcat_ID [ REV_mcat(0) ] is a long integer AutoNumber in the Access 2000
database & is the tables Primary Key.
I've come across this before on another project I was fiddling with, in the
end I just completly change the entire database / code to work around the
problem. I can't see away round it this time though.

I guess that it is probably something obvious, or a rule I don't know of.
I've just been staring at it for so long, I'm suffering code blindness.

Thanks.

Chris
 
C

Chris Tilley - HPC:Factor

Thank-you both very much for your suggestions!
Both CInt() and Clng() worked a treat!

I'm much obliged.

Chris

Curt_C said:
try using a convert to ensure the same datatype for comparison CStr() or
CInt()


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Chris Tilley - HPC:Factor said:
Hi,

I'm utterly confounded by this one. There must be some sort of rule that
I don't know of. I'd consider myself a Newbie+1, so be gentle.

I have a database connection (working A-Ok) and a Query String value from a
form (passed using GET & working Ok). The server is IIS5.

What I'm trying to do is get a simple IF statement to work accross the
two
numeric values. Once from a database and one from a Query String.

If %Database value% = %query string value% then
response.write("something")
else
response.write("nothing")
end if

...but it's not working. It always without fail responds with "nothing".
If I response.write the database variable and the query strings the
values
are all numeric and there is always going to be a match. There are only 3
records in the database and 3 options on the form.

If I change it to %Database value%=%Database value% then it works,
specifying "something" on all the results. If I manually place a numeric
value into the code in place of %Query string value% it works as it
should
do, except that of course it's static.

Here is the entire code segment:

<%
checkmcat=Request.Querystring("mstrcat")
SQLREVMCAT="SELECT TBL_revmcat.revmcat_ID, TBL_revmcat.revmcat_Name FROM
TBL_revmcat ORDER BY TBL_revmcat.revmcat_Name"
set revmcat = server.createobject("ADODB.Connection")
revmcat.open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/database.mdb")
set REV_mcat=revmcat.execute(SQLREVMCAT)
%>

<% do while not REV_mcat.eof %>
<option<% if REV_mcat(0) = checkmcat then
response.write(" SELECTED")
else
response.write("")
end if %> value="<%= REV_mcat(0) %>">- <%= REV_mcat(1)
%> said:
<%REV_mcat.movenext
loop%>
<% revmcat.close %>
</select>

revmcat_ID [ REV_mcat(0) ] is a long integer AutoNumber in the Access
2000
database & is the tables Primary Key.
I've come across this before on another project I was fiddling with, in the
end I just completly change the entire database / code to work around the
problem. I can't see away round it this time though.

I guess that it is probably something obvious, or a rule I don't know of.
I've just been staring at it for so long, I'm suffering code blindness.

Thanks.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top