Re: if statement comparing variable
From: Bob Barrows (reb01501_at_NOyahoo.SPAMcom)
Date: 02/29/04
- Next message: Mike Haas: "Re: if statement comparing variable"
- Previous message: Roji. P. Thomas: "Re: if statement comparing variable"
- In reply to: Michael Haas: "if statement comparing variable"
- Next in thread: Mike Haas: "Re: if statement comparing variable"
- Reply: Mike Haas: "Re: if statement comparing variable"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 29 Feb 2004 10:54:38 -0500
Michael Haas wrote:
> I'm trying to use a variable of retrieved via request from a form to
> select records.I'm pretty sure I am having a basic syntax error or
> something else basic.
> I retrieve the variable from a prevous form:
> section_id = request("section_id")
>
> I then retrieve some records and run the compare, if i use the actual
> value it works:
> if rsArticles("tbl_articles.section_id") = "1" then
This line is not giving you an error?? Do you have On Error Resume Next in
your code? Comment it out. You will see an error generated by this line. You
cannot refer to a recordset field using the table name like this. You can
only use:
a) the ordinal position of the field in the Fields collection:
rsArticles(1).value ' refers to second field in collection
b) the column name or column alias
rsArticles("section_id")
If you have more than one field called "section_id" in the results, then:
1) If both fields contain the same information - Stop writing inefficient
code! Your goal should be to bring as little data across the network as
possible. Using "Select *" defeats that goal. Don't bring the same
information across the network twice!
2) If the fields contain dissimilar information, then you need to assign
aliases to the columns so they will have different names in the recordset:
Select tbl_articles.section_id AS articles_section_id, ...
This will allow you to refer to it as
rsArticles("articles_section_id")
Your following description is unclear, and I suspect the results are being
clouded by the error in your reference to the recordset field.
>
> however if I substitute the variable section_id which equals 1 , it
> fails the compare and moves on to the else:
> if rsArticles("tbl_articles.section_id") = section_id then
>
> if I call the section_id value elsewhere it shows that it is set to 1,
> so I know it's being passed, <%=section_id%> returns 1
>
> What am I missing?
Bob Barrows
-- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
- Next message: Mike Haas: "Re: if statement comparing variable"
- Previous message: Roji. P. Thomas: "Re: if statement comparing variable"
- In reply to: Michael Haas: "if statement comparing variable"
- Next in thread: Mike Haas: "Re: if statement comparing variable"
- Reply: Mike Haas: "Re: if statement comparing variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|