471,108 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

asp if statement problem

120 100+
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 objRSLGWMANGLAYVR("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.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'CHECK FOR PRICES
  3. DIM objLGWMANGLAYVR
  4. Set objLGWMANGLAYVR = Server.CreateObject("ADODB.Connection")
  5. objLGWMANGLAYVR.ConnectionString = "Provider=SQLOLEDB;Data Source=IPREMOVED;" & _
  6. "Initial Catalog=Prices;User ID=IDREMOVED;Password=PASSREMOVED"
  7. objLGWMANGLAYVR.Open
  8.  
  9. DIM LGWMANGLAYVR
  10. LGWMANGLAYVR = "SELECT * FROM UK_Specials WHERE ID IN (7,11,15)"
  11.  
  12. DIM objRSLGWMANGLAYVR
  13. Set objRSLGWMANGLAYVR = Server.CreateObject("ADODB.Recordset")
  14. objRSLGWMANGLAYVR.Open LGWMANGLAYVR, objLGWMANGLAYVR
  15.  
  16. IF objRSLGWMANGLAYVR("ID") = 11 THEN
  17.  
  18. Response.Write "<div style=""background:red"">" & objRSLGWMANGLAYVR("Flight_Route") & "</div>"
  19.  
  20. End if
  21.  
  22. objRSLGWMANGLAYVR.Close
  23. Set objRSLGWMANGLAYVR = Nothing
  24. objLGWMANGLAYVR.Close
  25. Set objLGWMANGLAYVR = Nothing
  26. %>
can someone please shed some light?
Nov 17 '10 #1
10 1818
code green
1,726 Expert 1GB
I believe the problem is IF objRSLGWMANGLAYVR("ID") = 11 THEN which I believe to be valid code
Valid code yes but a common mistake when learning
Expand|Select|Wrap|Line Numbers
  1. IF objRSLGWMANGLAYVR("ID") == 11 
Nov 17 '10 #2
omar999
120 100+
hi code green - do you mind please explaining the difference between IF objRSLGWMANGLAYVR("ID") = 11 THEN and IF objRSLGWMANGLAYVR("ID") == 11 ??

I've tried IF objRSLGWMANGLAYVR("ID") == 11 and im getting a syntax error on the double equals mark...
Nov 17 '10 #3
code green
1,726 Expert 1GB
Apologies.
I didn't notice it was VB.
'==' is wrong.
I will have another look.
Nov 17 '10 #4
jhardman
3,406 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. if obj("Id") = "11" then
try it, the script might be interpretting it as text.

Jared
Nov 18 '10 #5
omar999
120 100+
Expand|Select|Wrap|Line Numbers
  1. if obj("Id") = "11" then
didnt work either... any other ideas?
Nov 26 '10 #6
jhardman
3,406 Expert 2GB
Loop thru the recordset and print everything - that's my standard troubleshooting procedure. Let me know if you need help with your code. Jared
Nov 26 '10 #7
omar999
120 100+
hi again jared : )

ok I've looped

Expand|Select|Wrap|Line Numbers
  1. SQL = "SELECT * FROM UK_Specials WHERE ID IN (7,11,15)"
  2.  
  3. DIM objRS
  4. Set objRS = Server.CreateObject("ADODB.Recordset")
  5. objRS.Open SQL, objConn
  6.  
  7. Do while not objRS.Eof
  8.  
  9. For x=1 To 5
  10. Response.Write objRS("ID") & " " & objRS("Flight_Route") & " &pound; " & objRS("Price_Band_" & x) & "&nbsp;"
  11. Response.Write objRS("Month_Band_" & x) & "&nbsp;" & objRS("Date_Band_" & x)
  12. Next
  13.  
  14. Response.Write "<br />"
  15.  
  16. 'move to the next record in the recordset
  17. objRS.movenext
  18.  
  19. Loop
above code works fine and this is what is prints out
Expand|Select|Wrap|Line Numbers
  1. 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
  2. 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
  3. 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.
Nov 27 '10 #8
jhardman
3,406 Expert 2GB
Next try printing out the data type
Expand|Select|Wrap|Line Numbers
  1. for each x in objRS
  2.    Response.write x.name & ": "& x.value & " (" & x.type & ")<br" &vbnewline
  3. Next
Nov 27 '10 #9
omar999
120 100+
im not sure where im going wrong but I've tried your suggestion but im receiving an error
Expand|Select|Wrap|Line Numbers
  1. Do while not objRS.Eof
  2.  
  3. for each x in objRS
  4.    Response.write x.name & ": "& x.value & " (" & x.type & ")<br />" 
  5. Next
  6.  
  7. 'move to the next record in the recordset
  8. objRS.movenext
  9.  
  10. Loop
error
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method
/test.asp, line 18

please advise
Omar.
Dec 2 '10 #10
jhardman
3,406 Expert 2GB
probably the x.value is bad. Try objRS(x) or objRS(x.name) instead.

Jared
Dec 2 '10 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Graham James Campbell CS2000 | last post: by
reply views Thread by Gary Bouchard | last post: by
13 posts views Thread by kieran | last post: by
6 posts views Thread by DLP22192 | last post: by
1 post views Thread by Ian Davies | last post: by
4 posts views Thread by bokke | last post: by
5 posts views Thread by JamesHoward | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.