Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > *pls help (3 day bug)* If statement not returning TRUE when it should

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-03, 04:27
corporate_targe corporate_targe is offline
Registered User
 
Join Date: May 2003
Posts: 18
*pls help (3 day bug)* If statement not returning TRUE when it should

I've had this bug for days now, please take a look to see if you can help. Thx

I made an html table to store values that VBscript pulls from an Microsoft Access data base. I modified code from w3school to do this. Here's the link: http://www.w3schools.com/ado/ado_display.asp.
All I change are the path, table, and field names. It works fine; It prints out the DB info in a table.

However, when I add a simple if statement (poined out in the code below) to ensure that the only data that gets printed is that which has the same zip code as the zip code that the user entered into the html field, nothing gets printed. The if statement always evaluates FALSE, even though I've checked the 2 sides of the condition statement, and they match up. Here's the code:

<!DOCTYPE asp>
<% Response.Buffer = True %>

<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\RH25.mdb"
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT zip, email, skills FROM members"
rs.Open sql, conn
zip = rs("zip")
zw = request.querystring("zipWanted")
response.write "zip= " & zip & " zw= " & zw
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td>
<%if zip = zw Then <----here's the if statement
Response.Write (x.value)
end if%>
</td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table></body>
</html>

Thx again.
Reply With Quote
  #2 (permalink)  
Old 05-12-03, 06:06
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
Re: *pls help (3 day bug)* If statement not returning TRUE when it should

You are setting zip = rs("zip") only for the first record. In your loop to process all the records, you do not reset zip so it still has the same value as it was originally set to. Should be something like this:

Code:
<%do until rs.EOF%> <tr> <%for each x in rs.Fields zip = rs("zip") %> <td> <%if zip = zw Then <----here's the if statement Response.Write (x.value) end if%> </td> <%next rs.MoveNext%> </tr> <%loop

Actually, this isn't a good way to do what you want anyway. If you are only interested in records where zip = zw then you should put that condition in the WHERE clause of your SELECT.
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #3 (permalink)  
Old 05-12-03, 17:16
corporate_targe corporate_targe is offline
Registered User
 
Join Date: May 2003
Posts: 18
I try to do what you suggest, but i get this error:

Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/RH25/listings_where.asp, line 20

Where line 20 is: rs.open sql, conn

Here's lines 1-20 of the code i'm using:

<% Option Explicit %>

<% Response.Buffer = True %>

<!-- #include file="adovbs.inc" -->

<html>
<body>
<%
dim zw
dim conn
dim sql
dim rs
zw = CStr(Request.Querystring("zipwanted"))
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\RH25.mdb"
sql="SELECT * FROM members WHERE zip='" & zw & "'"
set rs = Server.CreateObject("ADODB.recordset")
rs.open sql, conn

Thx again
Reply With Quote
  #4 (permalink)  
Old 05-13-03, 07:28
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
What is the data type of column members.zip? If it is a number then you don't want the single quotes around the zw value.
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On