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

IF Statement

P: n/a
How can I do the following:

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

Thanks
Jul 19 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
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!
"Keith" <@.> wrote in message news:#E*************@tk2msftngp13.phx.gbl...
How can I do the following:

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

Thanks

Jul 19 '05 #2

P: n/a
set rs = conn.execute(sql)
if rs.eof then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if
--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message news:#E*************@tk2msftngp13.phx.gbl...
How can I do the following:

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

Thanks

Jul 19 '05 #3

P: n/a
> 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
Jul 19 '05 #4

P: n/a
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
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
set rs = conn.execute(sql)
if rs.eof then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if
--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message news:#E*************@tk2msftngp13.phx.gbl...
How can I do the following:

If recordset is empty, redirect to page1 but if recordset has something

in,
redirect to page 2.

Thanks


Jul 19 '05 #5

P: n/a
I actually generally use;

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

Just figured I'd be creative :o\

--

Regards

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

Keeping it FREE!
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:#s**************@TK2MSFTNGP09.phx.gbl...
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

Jul 19 '05 #6

P: n/a
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!
"Keith" <@.> wrote in message news:u$**************@TK2MSFTNGP10.phx.gbl...
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
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
set rs = conn.execute(sql)
if rs.eof then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if
--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message news:#E*************@tk2msftngp13.phx.gbl...
How can I do the following:

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

Thanks



Jul 19 '05 #7

P: n/a
Keith wrote:
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.
Jul 19 '05 #8

P: n/a
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

Steven Burn wrote:
I actually generally use;

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

Just figured I'd be creative :o\
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:#s**************@TK2MSFTNGP09.phx.gbl...
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


--
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"
Jul 19 '05 #9

P: n/a
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!
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
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

Steven Burn wrote:
I actually generally use;

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

Just figured I'd be creative :o\
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:#s**************@TK2MSFTNGP09.phx.gbl...
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


--
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"

Jul 19 '05 #10

P: n/a
> 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?

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #11

P: n/a
Thanks everyone for your help

"Keith" <@.> wrote in message news:%2***************@tk2msftngp13.phx.gbl...
How can I do the following:

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

Thanks

Jul 19 '05 #12

P: n/a
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

Steven Burn wrote:
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?)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
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

Steven Burn wrote:
I actually generally use;

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

Just figured I'd be creative :o\
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:#s**************@TK2MSFTNGP09.phx.gbl...
> 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


--
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"


--
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"
Jul 19 '05 #13

P: n/a
Bob,
To be honest, I didn't know about the two ad's you mentioned :o\

Thanks for the info :o)

--

Regards

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

Keeping it FREE!
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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

Steven Burn wrote:
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?)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
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

Steven Burn wrote:
I actually generally use;

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

Just figured I'd be creative :o\
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:#s**************@TK2MSFTNGP09.phx.gbl...
>> 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

--
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"


--
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"

Jul 19 '05 #14

P: n/a
ooo, nice info... cheers Aaron :o) (suddenly I feel like an edgit, lol)

--

Regards

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

Keeping it FREE!
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:uo*************@TK2MSFTNGP12.phx.gbl...
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?

--
http://www.aspfaq.com/
(Reverse address to reply.)

Jul 19 '05 #15

P: n/a
Go here:
http://msdn.microsoft.com/library/en...umerations.asp

From which you can link to :
http://msdn.microsoft.com/library/en...cationenum.asp

and
http://msdn.microsoft.com/library/en...ortypeenum.asp

Bob Barrows

Steven Burn wrote:
Bob,
To be honest, I didn't know about the two ad's you mentioned :o\

Thanks for the info :o)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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

Steven Burn wrote:
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?)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
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

Steven Burn wrote:
> I actually generally use;
>
> If rst.RecordCount > 0 then
> '// Something
> End If
>
> Just figured I'd be creative :o\
>
>
> "Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
> news:#s**************@TK2MSFTNGP09.phx.gbl...
>>> 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

--
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"


--
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"


--
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"
Jul 19 '05 #16

P: n/a
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
"Steven Burn" <pv*@noyb.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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!
"Keith" <@.> wrote in message

news:u$**************@TK2MSFTNGP10.phx.gbl...
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
"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
set rs = conn.execute(sql)
if rs.eof then
response.redirect("page1.asp")
else
response.redirect("page2.asp")
end if
--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message

news:#E*************@tk2msftngp13.phx.gbl... > How can I do the following:
>
> If recordset is empty, redirect to page1 but if recordset has something in,
> redirect to page 2.
>
> Thanks
>
>



Jul 19 '05 #17

P: n/a
ooo nice one, thankyou :o)

--

Regards

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

Keeping it FREE!
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:#Y*************@tk2msftngp13.phx.gbl...
Go here:
http://msdn.microsoft.com/library/en...umerations.asp
From which you can link to :
http://msdn.microsoft.com/library/en...locationenum.a
sp
and
http://msdn.microsoft.com/library/en...ortypeenum.asp

Bob Barrows

Steven Burn wrote:
Bob,
To be honest, I didn't know about the two ad's you mentioned :o\

Thanks for the info :o)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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

Steven Burn wrote:
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?)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
> 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
>
> Steven Burn wrote:
>> I actually generally use;
>>
>> If rst.RecordCount > 0 then
>> '// Something
>> End If
>>
>> Just figured I'd be creative :o\
>>
>>
>> "Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
>> news:#s**************@TK2MSFTNGP09.phx.gbl...
>>>> 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
>
> --
> 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"

--
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"


--
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"

Jul 19 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.