473,382 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1964
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

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

Similar topics

7
by: Graham James Campbell CS2000 | last post by:
Having a nightmare problem with this and would appreciate any and all help. The situation is I want to move from a webform and format the user inputted text into some html I am storing in a...
0
by: Gary Bouchard | last post by:
MYSQL Version 4.0.15 Can some anyone tell me what is wrong with the following statement; select bookings.key1,bookings.surname,bookings.firstname,bookings.bookingseqno,bookings.filetype from...
13
by: kieran | last post by:
Hi, I have the following SQL statement which is pulling a few details from a database. As you can see, there is only the one table from which i am creating a temporary copy. The reason I do...
6
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
1
by: Ian Davies | last post by:
I am using a simple delete statement in my php script (below) $q = "DELETE FROM commenttype WHERE TypeID=".$_POST; the problem is it doesnt delete the whole row it only deletes the text in one...
4
by: bokke | last post by:
Hi, I have a page that has several stories that run on it from a mysql database. Right now I use this code: <img src="Images/NewsPics/<?php echo $row;?>.jpg" border="1"to display the image. ...
5
by: JamesHoward | last post by:
I have a problem with python's asyncore module throwing a bad file descriptor error. The code might be difficult to copy here, but the problem is essentially: The server wants to sever the...
2
by: gool | last post by:
Hi, I am writing this piece of code: $sqlquery="WITH journey (TO_TOWN, STEPS, DISTANCE, WAY) AS (SELECT DISTINCT JNY_FROM_TOWN, 0, 0, CAST('PARIS' AS VARCHAR(MAX)) FROM T_JOURNEY ...
6
by: jephperro | last post by:
Hi there, I'm having a really tough time with a SQL statement and I am wondering if someone is able to help out or point me in the right direction. I have a table of names which can be very...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Incorrect syntax near '<'. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.