#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    17
    Rep Power
    0

    Conditional Statement Not Working...


    What's wrong with this syntax?

    Code:
    <%
    saleid = Request.QueryString("saleid")
    Response.Write(saleid)
    set conn = server.CreateObject ("ADODB.Connection")
      conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("users.mdb")
       set rs = server.CreateObject ("ADODB.Recordset")
    rs.open "SELECT * FROM Sales ", conn, 3,3
    do while not rs.EOF
    Response.Write(rs.Fields("id"))
    If rs.Fields("id") = saleid then
    Response.Write(rs("id"))
    Response.Write(rs("level2id"))
    Response.Write(rs("itemdesc"))
    Response.Write(rs("itemprice"))
    Response.Write(rs("saletime"))
    else
    Response.Write("xxx")
    end if
    rs.Movenext
    loop
    
    
    set rs = nothing
    set conn = nothing
    
    
    
    %>
    I am not getting an error, but this is what it outputs:

    2121xxx22xxx23xxx24xxx26xxx27xxx28xxx29xxx31xxx32xxx33xxx


    You can see that saleid DOES equal rs.fields("id") for the first field in database.

    Thanks!

    Gabriel
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,441
    Rep Power
    4539
    You could include some line breaks in your debug outputs to help you see where things are going wrong.

    As a comment, selecting all the records from your DB then filtering them in a loop is kind of an unnecessary step and wastes resources. Also imagine how your page will run when you have a couple million sales records.

    I'd add a WHERE clause in your sql so you get back a recordset with only what you want.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo