473,664 Members | 2,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do While not Statement

Ben
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
9 9181
Why've you got them in 2 DW loops?

Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If

'-----Figures out how they heard about the program

If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext
Loop

--

Regards

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

Keeping it FREE!
"Ben" <Be************ @langley.af.mil > wrote in message
news:#j******** ******@tk2msftn gp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #2
Why do you need to perform the loop twice? One problem is that in your
first loop, you move to the EOF. When you start your second loop, you're
already at EOF, so where is it supposed to go? The Do never enters...

Isn't this simply re-written as:

do while not rs.eof
' do stuff from first loop
' do stuff from second loop
rs.movenext
loop

You should also review http://www.aspfaq.com/2191 ... I see no reason for
ADODB.Recordset here.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ben" <Be************ @langley.af.mil > wrote in message
news:#j******** ******@tk2msftn gp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #3
Previous responses provided a better solution... and Aaron hints as to why
the second loop returns nothing. That being said..and noting that *I* would
use the aformentioned solutions.. to answer your specific question; to make
your code work add rs_Report.Movef irst prior to starting the second loop.


"Ben" <Be************ @langley.af.mil > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4
How about just doing a count query or queries?
intMale = odoCon.Execute( "SELECT COUNT(gender) FROM tblUsers WHERE
gender='male'") .Fields.Item(0) .Value
intFemale = odoCon.Execute( "SELECT COUNT(gender) FROM tblUsers WHERE
gender='female' ").Fields.Item( 0).Value
intBasePaper = odoCon.Execute( "SELECT COUNT(referral) FROM tblUsers WHERE
referral='Base Paper'").Fields .Item(0).Value

(Some would argue against the methods above, however.)

For sexes, you could also do "SELECT gender,COUNT(ge nder) FROM tblUsers
GROUP BY gender ORDER BY gender" to gram male and female at once.

Ray at work


"Ben" <Be************ @langley.af.mil > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #5
Depending on the database and version, you can probably do this in one
query, returning one row, and eliminating the need to loop at all, never
mind multiple times.

For SQL Server:

SELECT
male = SUM(CASE gender WHEN 'male' THEN 1 ELSE 0 END),
female = SUM(CASE gender WHEN 'female' THEN 1 ELSE 0 END),
basePaper = SUM(CASE referral WHEN 'Base Paper' THEN 1 ELSE 0 END)
FROM tblUsers

I'm continually amazed that people think it is too much work, or not
valuable enough, to include what type of database they are working with...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:OW******** ******@TK2MSFTN GP09.phx.gbl...
How about just doing a count query or queries?
intMale = odoCon.Execute( "SELECT COUNT(gender) FROM tblUsers WHERE
gender='male'") .Fields.Item(0) .Value
intFemale = odoCon.Execute( "SELECT COUNT(gender) FROM tblUsers WHERE
gender='female' ").Fields.Item( 0).Value
intBasePaper = odoCon.Execute( "SELECT COUNT(referral) FROM tblUsers WHERE
referral='Base Paper'").Fields .Item(0).Value

(Some would argue against the methods above, however.)

For sexes, you could also do "SELECT gender,COUNT(ge nder) FROM tblUsers
GROUP BY gender ORDER BY gender" to gram male and female at once.

Ray at work


"Ben" <Be************ @langley.af.mil > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenB ase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gend er") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveN ext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("refe rral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveN ext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 19 '05 #6
> I'm continually amazed that people think it is too much work, or not
valuable enough, to include what type of database they are working with...


http://www.aspfaq.com/5009
(There there, that feels better.)
Jul 19 '05 #7
Ben
>do while not rs.eof
' do stuff from first loop
' do stuff from second loop
rs.movenext
loop
Aaron: This is what Im going to end up doing, thanks for the insight, Im
still a beginner at this.
intMale = odoCon.Execute( "SELECT COUNT(gender) FROM >tblUsers WHERE
gender='male'" ).Fields.Item(0 ).Value
intFemale = odoCon.Execute( "SELECT COUNT(gender) FROM >tblUsers WHERE
gender='female '").Fields.Item (0).Value
intBasePaper = odoCon.Execute( "SELECT COUNT(referral) FROM >tblUsers WHEREreferral='Ba se Paper'").Fields .Item(0).Value
Ray: Why would some argue against this method?
I'm continually amazed that people think it is too much >work, or not
valuable enough, to include what type of database they are >working

with...

Aaron: Sorry about the oversight,it's an Access database until reading
the article I didn't realize that it was important, but now I know
better. Im still new to all of this(SQL, ASP, Access), so any help is
appreciated.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #8
Ooh, and I didn't know about 5008. I like that one too. :]

Ray at home

"Aaron Bertrand - MVP" <aa***@TRASHasp faq.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
http://www.aspfaq.com/5009
(There there, that feels better.)

Jul 19 '05 #9

"Ben" <Be************ @langley.af.mil > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
intMale = odoCon.Execute( "SELECT COUNT(gender) FROM >tblUsers WHERE
gender='male'" ).Fields.Item(0 ).Value
Ray: Why would some argue against this method?


The argument would come from doing this:

someValue = ADOObject.Execu te("a query").Fields. Item(0).Value

as opposed to:

Set rs = ADOObject.Execu te("a query")
someValue = rs.Fields.Item( 0).Value
rs.Close
Set rs = Nothing
When you implicitly create an object as is done in code sample 1, that
object won't be destroyed until the ASP engine is finished processing the
whole page and is cleaning up. So, it is not the most efficient way of
doing things. You typically want to create your recordset (or any object),
just before you need it and close and destroy it as soon as you no longer
need it. Does this matter or will you notice a difference in page load
times? No. If you get to that point, you won't be using Access anymore
anyway. :]

Ray at home
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3577
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a very early draft for a new "assert" syntax: This was inspired in Ruby's assert syntax. I'm not familiar with Ruby at all, so the chances are that this piece of code is broken, but I think the idea is very obvious. In Ruby, assert is simply a...
15
2797
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
2556
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
37
3284
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html PEP: XXX Title: The create statement
18
2708
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html In this post, I'm especially soliciting review of Carl Banks's point (now discussed under Open Issues) which asks if it would be better to have the create statement translated into:
28
2933
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions! PEP: 359 Title: The "make" Statement Version: $Revision: 45366 $ Last-Modified: $Date: 2006-04-13 07:36:24 -0600 (Thu, 13 Apr 2006) $
7
2688
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
19
8363
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
18
7958
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp defintion of "expression" and "statement"? What is the difference between an expression and a statement?
23
2059
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;'));
0
8437
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.