By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

asp if statement problem

100+
P: 120
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
Share this Question
Share on Google+
10 Replies


code green
Expert 100+
P: 1,726
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

100+
P: 120
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
Expert 100+
P: 1,726
Apologies.
I didn't notice it was VB.
'==' is wrong.
I will have another look.
Nov 17 '10 #4

jhardman
Expert 2.5K+
P: 3,405
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

100+
P: 120
Expand|Select|Wrap|Line Numbers
  1. if obj("Id") = "11" then
didnt work either... any other ideas?
Nov 26 '10 #6

jhardman
Expert 2.5K+
P: 3,405
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

100+
P: 120
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
Expert 2.5K+
P: 3,405
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

100+
P: 120
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
Expert 2.5K+
P: 3,405
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.