IF Statement

K

Keith

How can I do the following:

If recordset is empty, redirect to page1 but if recordset has something in,
redirect to page 2.

Thanks
 
S

Steven Burn

valTemp = rst.RecordCount
Select Case valTemp
Case 0
Response.Redirect "nothing_in_there.asp"
Case Else
Response.Redirect "something_in_there.asp"
End Select

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
A

Aaron [SQL Server MVP]

set rs = conn.execute(sql)
if rs.eof then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if
 
A

Aaron [SQL Server MVP]

valTemp = rst.RecordCount
Select Case valTemp
Case 0
Response.Redirect "nothing_in_there.asp"
Case Else
Response.Redirect "something_in_there.asp"
End Select

Except, RecordCount isn't available with the default cursor (-1 is the
default), so your Else will probably always fire.

The EOF property will tell you if the resultset is empty without having to
rely on a count.

A
 
S

Steven Burn

I actually generally use;

If rst.RecordCount > 0 then
'// Something
End If

Just figured I'd be creative :eek:\

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
K

Keith

How (if possible) could I modify this so that it redirects to page 1 if RS
was NOT eof OR if a sessionvariable1 contained value1

If the session variable containes any other value or if the rs IS eof then
redirect to page 2

Thanks
 
S

Steven Burn

set rs = conn.execute(sql)
if not rs.eof or sessionvarible1 = "1" then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
D

Dave Anderson

Keith said:
How can I do the following:

If recordset is empty, redirect to page1 but if recordset has
something in, redirect to page 2.

if (RS.EOF) {
<<< do stuff, close connection, etc. >>>
Response.Redirect("p1.asp")
}

<<< do other stuff, close RS & CN >>>
Response.Redirect("p2.asp")



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
B

Bob Barrows [MVP]

Again, this use of RecordCount requires the use of an expensive cursor type.
Use the EOF property instead (as Aaron correctly suggested):

'//immediately after opening the recordset:
If not rst.EOF then
'//recordset is not empty
else
'//recordset is empty
end if

Bob Barrows
 
S

Steven Burn

Been taking a look into it since Aaron mentioned it ;o) (so far, I can't see
the difference as far as performance is concerned?)

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
A

Aaron [SQL Server MVP]

Been taking a look into it since Aaron mentioned it ;o) (so far, I can't
see
the difference as far as performance is concerned?)

The performance comes in when you switch to using an expensive, non-default
recordset just to get the recordcount property.

http://www.aspfaq.com/2191

He wasn't making a decision based on a specific recordcount, just an empty /
non-empty set. So why go to all that trouble when you already have an EOF
property to check?
 
B

Bob Barrows [MVP]

On its own, you might not. Did you switch to using the less expensive cursor
type and location: adOpenForwardOnly and adUseServer? Even if you did, you
probably did not notice the decrease in memory resources and cpu cycles used
on both the web and database servers when opening the less expensive cursor
type. But I guarantee you that the servers did "notice" it, and if you make
the change in enough pages that were using the more expensive cursor types,
you may notice an increase in overall performance of your server.

Of course, if your web server does not get a lot of usage, you still might
not notice it, but that does not mean that this is not a Best Practice which
you should get into the habit of using:

Use the cheapest cursor type required to support your application's
functionality. For the most part in ASP, you will not need to use a
bookmarkable cursor (i.e., a cursor which supports scrolling and
recordcount), so you should use the default cursor in almost all cases. If
you DO need extra functionality (filter, etc.), then make sure you
disconnect the recordset while processing it.

Bob Barrows
 
M

Mark Schupp

I would strongly suggest closing the recordset and connection before the
redirect. This should take place automatically when the page goes out of
score but I am a strong believer in "if you open it, close it" and "if you
create it, destroy it" (never have liked automatic garbage collectors).

set rs = conn.execute(sql)
if not rs.eof or sessionvarible1 = "1" then
targeturl = "page1.asp"
else
targeturl = "page2.asp"
end if

rs.close
set rs=nothing
conn.close
set conn=nothing

response.redirect targeturl

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top