Two simple ASP questions
am 14.06.2006 02:54:56 von brian.lukoff
Two simple ASP questions:
1. If I am iterating through a recordset, and then for each record
iterating through the fields one or more times (using a For Each...Next
loop), am I assured that the order in which I iterate through the
fields will remain unchanged throughout the iteration of the records?
Example pseudocode:
Set rs = ...
For Each f In rs.Fields
Response.Write f.Name
Next
Do Until rs.Eof
For Each f In rs.Fields
Response.Write f.Name
Next
rs.MoveNext
Loop
[The code should print the names of the fields over and over again, but
in the same order.]
2. Is it really necessary to issue a rs.MoveFirst command before
iterating through a recordset? Is there ever a situation where I could
obtain a recordset via a SQL query (see pseudocode below) and would not
get all of the records in the data set?
Set rs = ...
Do Until rs.Eof
...
rs.MoveNext
Loop
Re: Two simple ASP questions
am 14.06.2006 15:53:33 von avidfan
On 13 Jun 2006 17:54:56 -0700, brian.lukoff@gmail.com wrote:
>Two simple ASP questions:
>
>1. If I am iterating through a recordset, and then for each record
>iterating through the fields one or more times (using a For Each...Next
>loop), am I assured that the order in which I iterate through the
>fields will remain unchanged throughout the iteration of the records?
>Example pseudocode:
>
>Set rs = ...
>For Each f In rs.Fields
> Response.Write f.Name
>Next
>Do Until rs.Eof
> For Each f In rs.Fields
> Response.Write f.Name
> Next
> rs.MoveNext
>Loop
>
>[The code should print the names of the fields over and over again, but
>in the same order.]
>
The order of the fields is determined by the Query - If you use the 'Select * from Table where...' form , then it will
be the order they appear in the table ( using Select *, however, is not a good practice)..
>2. Is it really necessary to issue a rs.MoveFirst command before
>iterating through a recordset? Is there ever a situation where I could
>obtain a recordset via a SQL query (see pseudocode below) and would not
>get all of the records in the data set?
>
>Set rs = ...
>Do Until rs.Eof
> ...
> rs.MoveNext
>Loop
Not certain about this one, but none of my code that uses Recordsets has a MoveFirst ... I may just be lucky however.
Re: Two simple ASP questions
am 14.06.2006 16:42:05 von ten.xoc
> Set rs = ...
> Do Until rs.Eof
Just a personal preference, I always use Do While Not, not Do Until. And I
don't think I have ever seen a code sample that uses Do Until.
A
Re: Two simple ASP questions
am 14.06.2006 19:45:12 von exjxw.hannivoort
Aaron Bertrand [SQL Server MVP] wrote on 14 jun 2006 in
microsoft.public.inetserver.asp.db:
>> Set rs = ...
>> Do Until rs.Eof
>
> Just a personal preference, I always use Do While Not, not Do Until.
> And I don't think I have ever seen a code sample that uses Do Until.
Per definitoion the two are the same, methinks.
Any argument why they should not be?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Two simple ASP questions
am 16.06.2006 20:54:01 von JohnBeschler
Seems to me I remember from an old programming class years ago that the
difference between these two was that in one case, the loop would ALWAYS get
executed at least one time, wherease in the other that was not true.
However, I do not remember which was which, so it may be a moot point anyway!
:)
"Evertjan." wrote:
> Aaron Bertrand [SQL Server MVP] wrote on 14 jun 2006 in
> microsoft.public.inetserver.asp.db:
>
> >> Set rs = ...
> >> Do Until rs.Eof
> >
> > Just a personal preference, I always use Do While Not, not Do Until.
> > And I don't think I have ever seen a code sample that uses Do Until.
>
> Per definitoion the two are the same, methinks.
>
> Any argument why they should not be?
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
>
Re: Two simple ASP questions
am 16.06.2006 22:40:54 von Mike Brind
John Beschler wrote:
> "Evertjan." wrote:
>
> > Aaron Bertrand [SQL Server MVP] wrote on 14 jun 2006 in
> > microsoft.public.inetserver.asp.db:
> >
> > >> Set rs = ...
> > >> Do Until rs.Eof
> > >
> > > Just a personal preference, I always use Do While Not, not Do Until.
> > > And I don't think I have ever seen a code sample that uses Do Until.
> >
> > Per definitoion the two are the same, methinks.
> >
> > Any argument why they should not be?
> >
> >
> > --
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> >
>
> Seems to me I remember from an old programming class years ago that the
> difference between these two was that in one case, the loop would ALWAYS get
> executed at least one time, wherease in the other that was not true.
> However, I do not remember which was which, so it may be a moot point anyway!
> :)
>
Your classes must have been a long time ago...:-)
One executes while a condition is true, the other executes until a
condition is true. In other words, as Evertjan says, they are the
same.
What you probably half remember are the versions where the condition
comes after the code to be executed:
Do... Loop Until or Do... Loop While
In both of the above, you are guaranteed that the loop will execute at
least once. Personally, I've never seen either of these variations
actually in use :-)
--
Mike Brind
Re: Two simple ASP questions
am 16.06.2006 22:55:18 von ten.xoc
I never said any different. That's why I prefixed my message with, "just a
personal preference." Kind of like top-posting vs. bottom-posting.
Personally, I don't to scroll past crap I've already read to see the new
information. YMV.
> Per definitoion the two are the same, methinks.
Re: Two simple ASP questions
am 17.06.2006 01:27:37 von exjxw.hannivoort
Aaron Bertrand [SQL Server MVP] wrote on 16 jun 2006 in
microsoft.public.inetserver.asp.db:
>> Per definitoion the two are the same, methinks.
>
> I never said any different. That's why I prefixed my message with,
> "just a personal preference."
My response to that was not a critique.
Aaron, you can see in John Beschler's answer, that explicitly stating that
they are the same [do while not .. /do until .. ] is a good thing,
as it has helped at least one.
> Kind of like top-posting vs.
> bottom-posting. Personally, I don't to scroll past crap I've already
> read to see the new information.
So you will not read this, I presume?
> YMV.
??
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Two simple ASP questions
am 18.06.2006 20:54:57 von brian.lukoff
Aaron--
Do you know for sure if MoveFirst is ever required before iterating
through a recordset to get all of the records?
Brian
Aaron Bertrand [SQL Server MVP] wrote:
> > Set rs = ...
> > Do Until rs.Eof
>
> Just a personal preference, I always use Do While Not, not Do Until. And I
> don't think I have ever seen a code sample that uses Do Until.
>
> A
Re: Two simple ASP questions
am 18.06.2006 21:05:23 von reb01501
brian.lukoff@gmail.com wrote:
> Aaron--
>
> Do you know for sure if MoveFirst is ever required before iterating
> through a recordset to get all of the records?
>
It depends.
Immediately after opening a recordset, the cursor is automatically pointed
to the first record if records were returned. So, in this situation, the
MoveFirst is not needed, and may cause an error if the cursor type does not
support it.
If you've done any prior navigation through the recordset, or deleted any
records from it, then yes, a MoveFirst (after a test for BOF returns false)
is needed.
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"
Re: Two simple ASP questions
am 18.06.2006 22:36:53 von brian.lukoff
So to clarify, the following would always iterate through all of the
records in the recordset?
Set rs = conn.Execute(...)
Do Until rs.Eof
...
rs.MoveNext
Loop
Bob Barrows [MVP] wrote:
> brian.lukoff@gmail.com wrote:
> > Aaron--
> >
> > Do you know for sure if MoveFirst is ever required before iterating
> > through a recordset to get all of the records?
> >
>
> It depends.
>
> Immediately after opening a recordset, the cursor is automatically pointed
> to the first record if records were returned. So, in this situation, the
> MoveFirst is not needed, and may cause an error if the cursor type does not
> support it.
>
> If you've done any prior navigation through the recordset, or deleted any
> records from it, then yes, a MoveFirst (after a test for BOF returns false)
> is needed.
>
> 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"
Re: Two simple ASP questions
am 19.06.2006 02:27:58 von reb01501
That was your question?
The answer is yes.
Of course, there are more efficient techniques you could use: GetRows and
GetString.
http://www.aspfaq.com/show.asp?id=2467
Just checking: have you been to msdn.microsoft.com/library to read the
documentation?
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoa pireference.asp
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscsect ion1_ado.asp
brian.lukoff@gmail.com wrote:
> So to clarify, the following would always iterate through all of the
> records in the recordset?
>
> Set rs = conn.Execute(...)
> Do Until rs.Eof
> ...
> rs.MoveNext
> Loop
>
> Bob Barrows [MVP] wrote:
>> brian.lukoff@gmail.com wrote:
>>> Aaron--
>>>
>>> Do you know for sure if MoveFirst is ever required before iterating
>>> through a recordset to get all of the records?
>>>
>>
>> It depends.
>>
>> Immediately after opening a recordset, the cursor is automatically
>> pointed to the first record if records were returned. So, in this
>> situation, the MoveFirst is not needed, and may cause an error if
>> the cursor type does not support it.
>>
>> If you've done any prior navigation through the recordset, or
>> deleted any records from it, then yes, a MoveFirst (after a test for
>> BOF returns false) is needed.
>>
--
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"