Results 1 to 9 of 9
  1. #1
    Join Date
    May 2003
    Posts
    18

    Unanswered: If statement halts page load

    This page loads and works fine without the If statement. When the If statement is present, it doesn't get loaded. I'm new to ASP and Access. I think i have the Access part right since, again, the page loads without the if statement. Can anyone figure out what is wrong? Thx.

    <% Response.Buffer = True %>

    <html>
    <head>
    <title>Memeber Email Listing of the chosen zip code</title>
    </head>
    <body>

    <%
    Dim rs
    Set rs = Server.CreateObject ("ADODB.Recordset")

    rs.Open "members", "DSN=act"

    zipwanted = Request.Querystring("zipwanted")

    While Not rs.EOF
    If rs("zip") = request.querystring("zipwanted") Then
    Response.Write "Email : " & rs("email") & "<br>"
    Response.Write "Skills : " & rs("skills") & "<br>"
    Response.Write "Zip Code : " & rs("zip") & "<br>"
    Response.Write "<br>"
    rs.MoveNext
    End If
    Wend

    rs.Close
    Set rs = Nothing
    %>

    </body>
    </html>

  2. #2
    Join Date
    May 2003
    Posts
    18
    sorry, i've recently moved the End If to where it should be, before the rs.MoveNext statement.

    Now the problem is that records with the asked for zip don't show up. When i change the if statement from "=" to "<>", it prints the record, even though the record contains the zip that was asked for.

    Thx again.

  3. #3
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    Dear CT...

    I'm not an expert on data types, but my first inclination is that data types are perhaps part of your issue... because even though the data looks like it should match, it isn't matching.

    I would go about what you're apparently trying to do a bit differently, but for starters, why don't you just try changing things as follows:

    Code:
    Dim rs
    Set rs = Server.CreateObject ("ADODB.Recordset")
    rs.Open "members", "DSN=act"
    zipwanted = CStr(Request.Querystring("zipwanted"))
    
    While Not rs.EOF
        If rs("zip") = zipwanted Then 
            Response.Write "Email : " & rs("email") & "<br>"
            Response.Write "Skills : " & rs("skills") & "<br>"
            Response.Write "Zip Code : " & rs("zip") & "<br>"
            Response.Write "<br>"
        End If 
        rs.MoveNext
    Wend
    
    rs.Close
    Set rs = Nothing
    Personally, I would use SQL to filter the recordset first...

    Code:
    zw = CStr(Request.Querystring("zipwanted"))
    SQLx="SELECT * FROM members WHERE zip='" & zw & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open SQLx, "DSN=act"
    
    While Not rs.EOF
         Response.Write "Email : " & rs("email") & "<br>"
         Response.Write "Skills : " & rs("skills") & "<br>"
         Response.Write "Zip Code : " & rs("zip") & "<br>"
         Response.Write "<br>"
         rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    Good Luck....

    Tim
    Tim

  4. #4
    Join Date
    May 2003
    Posts
    18
    Thx Tim.

    Perhaps my configurationg is wrong somewher, because your code gave this error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    /RH25/listings.asp, line 59

    line 59 is: rs.Open SQLx, "DSN=act"

    What needs to be done to fix that?

    Thx again.

  5. #5
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    Originally posted by corporate_targe
    Thx Tim.

    Perhaps my configurationg is wrong somewher, because your code gave this error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    /RH25/listings.asp, line 59

    line 59 is: rs.Open SQLx, "DSN=act"

    What needs to be done to fix that?

    Thx again.
    Sorry, in my haste I assumed you had a connection object set up, and just copied and pasted what you had without really thinking...

    zw = CStr(Request.Querystring("zipwanted"))
    SQLx="SELECT * FROM members WHERE zip='" & zw & "'"
    adoConn="DSN=act"
    Set Q = Server.CreateObject("ADODB.Connection")
    Q.Open adoConn
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open SQLx, Q
    ... and then the rest of it...

    should do it I think.

    Tim
    Tim

  6. #6
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    I'm also assuming you have the DSN called 'act' set up on the server?

    Tim

    Originally posted by corporate_targe
    Thx Tim.

    Perhaps my configurationg is wrong somewher, because your code gave this error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    /RH25/listings.asp, line 59

    line 59 is: rs.Open SQLx, "DSN=act"

    What needs to be done to fix that?

    Thx again.
    Tim

  7. #7
    Join Date
    May 2003
    Posts
    18
    yes

  8. #8
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    Originally posted by corporate_targe
    yes
    did you set up the connection object per my previous post?
    Tim

  9. #9
    Join Date
    May 2003
    Posts
    18
    no, i had it set up and was able to print the contents of the database except when the if statement that checked rs("zip") against the zip entered was left out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •