asp if statement problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

    asp if statement problem

    can some one please shed some light on what is wrong with my code - im selecting 3 records and simply want to display the Flight_Route if the ID = 11. I believe the problem is IF objRSLGWMANGLAY VR("ID") = 11 THEN which I believe to be valid code but im not sure now

    the following code should output MANCHESTER to VANCOUVER [as this is what is on the sql table] inside a red div but instead does nothing. no errors either.

    Code:
    <%
    'CHECK FOR PRICES
    DIM objLGWMANGLAYVR
    Set objLGWMANGLAYVR = Server.CreateObject("ADODB.Connection")
    objLGWMANGLAYVR.ConnectionString = "Provider=SQLOLEDB;Data Source=IPREMOVED;" & _
    "Initial Catalog=Prices;User ID=IDREMOVED;Password=PASSREMOVED"
    objLGWMANGLAYVR.Open
    
    DIM LGWMANGLAYVR
    LGWMANGLAYVR = "SELECT * FROM UK_Specials WHERE ID IN (7,11,15)"
    
    DIM objRSLGWMANGLAYVR
    Set objRSLGWMANGLAYVR = Server.CreateObject("ADODB.Recordset")
    objRSLGWMANGLAYVR.Open LGWMANGLAYVR, objLGWMANGLAYVR
    
    IF objRSLGWMANGLAYVR("ID") = 11 THEN
    
    Response.Write "<div style=""background:red"">" & objRSLGWMANGLAYVR("Flight_Route") & "</div>"
    	  	
    End if
    
    objRSLGWMANGLAYVR.Close
    Set objRSLGWMANGLAYVR = Nothing
    objLGWMANGLAYVR.Close
    Set objLGWMANGLAYVR = Nothing
    %>
    can someone please shed some light?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I believe the problem is IF objRSLGWMANGLAY VR("ID") = 11 THEN which I believe to be valid code
    Valid code yes but a common mistake when learning
    Code:
    IF objRSLGWMANGLAYVR("ID") == 11

    Comment

    • omar999
      New Member
      • Mar 2010
      • 120

      #3
      hi code green - do you mind please explaining the difference between IF objRSLGWMANGLAY VR("ID") = 11 THEN and IF objRSLGWMANGLAY VR("ID") == 11 ??

      I've tried IF objRSLGWMANGLAY VR("ID") == 11 and im getting a syntax error on the double equals mark...

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        Apologies.
        I didn't notice it was VB.
        '==' is wrong.
        I will have another look.

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Code:
          if obj("Id") = "11" then
          try it, the script might be interpretting it as text.

          Jared

          Comment

          • omar999
            New Member
            • Mar 2010
            • 120

            #6
            Code:
            if obj("Id") = "11" then
            didnt work either... any other ideas?

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              Loop thru the recordset and print everything - that's my standard troubleshooting procedure. Let me know if you need help with your code. Jared

              Comment

              • omar999
                New Member
                • Mar 2010
                • 120

                #8
                hi again jared : )

                ok I've looped

                Code:
                SQL = "SELECT * FROM UK_Specials WHERE ID IN (7,11,15)"
                
                DIM objRS
                Set objRS = Server.CreateObject("ADODB.Recordset")
                objRS.Open SQL, objConn
                
                Do while not objRS.Eof
                
                For x=1 To 5
                Response.Write objRS("ID") & " " & objRS("Flight_Route") & " &pound; " & objRS("Price_Band_" & x) & "&nbsp;"
                Response.Write objRS("Month_Band_" & x) & "&nbsp;" & objRS("Date_Band_" & x)
                Next
                
                Response.Write "<br />"
                
                'move to the next record in the recordset
                objRS.movenext
                
                Loop
                above code works fine and this is what is prints out
                Code:
                7 GATWICK to VANCOUVER £  Nov NO FLIGHT7 GATWICK to VANCOUVER £ 299 Dec 97 GATWICK to VANCOUVER £ 299 Jan 13, 20, 277 GATWICK to VANCOUVER £ 199 Feb 37 GATWICK to VANCOUVER £  Mar No Flights in Winter
                11 MANCHESTER to VANCOUVER £  Nov NO FLIGHT11 MANCHESTER to VANCOUVER £ 369 Dec 2011 MANCHESTER to VANCOUVER £ 339 Jan 111 MANCHESTER to VANCOUVER £  Feb NO FLIGHT11 MANCHESTER to VANCOUVER £  Mar No Flights in Winter
                15 GLASGOW to VANCOUVER £  Nov No Flights in Winter15 GLASGOW to VANCOUVER £  Dec No Flights in Winter15 GLASGOW to VANCOUVER £  Jan No Flights in Winter15 GLASGOW to VANCOUVER £  Feb No Flights in Winter15 GLASGOW to VANCOUVER £  Mar No Flights in Winter
                i mainly want to know why if obj("Id") = "11" doesnt do anything..

                thanks in advance
                Omar.

                Comment

                • jhardman
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3405

                  #9
                  Next try printing out the data type
                  Code:
                  for each x in objRS
                     Response.write x.name & ": "& x.value & " (" & x.type & ")<br" &vbnewline
                  Next

                  Comment

                  • omar999
                    New Member
                    • Mar 2010
                    • 120

                    #10
                    im not sure where im going wrong but I've tried your suggestion but im receiving an error
                    Code:
                    Do while not objRS.Eof
                     
                    for each x in objRS
                       Response.write x.name & ": "& x.value & " (" & x.type & ")<br />" 
                    Next
                     
                    'move to the next record in the recordset
                    objRS.movenext
                     
                    Loop
                    error
                    Microsoft VBScript runtime error '800a01b6'
                    Object doesn't support this property or method
                    /test.asp, line 18

                    please advise
                    Omar.

                    Comment

                    • jhardman
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3405

                      #11
                      probably the x.value is bad. Try objRS(x) or objRS(x.name) instead.

                      Jared

                      Comment

                      Working...