Re: Top 10 items?
am 07.03.2006 12:56:28 von reb01501
TRB_NV wrote:
> For the heck of it and because it's a little more elegant, I used the
> TOP keyword. Thanks for your help. It's always nice to produce neat
> and clean code.
In that case, you might want to look into using GetRows instead of looping
through recordsets:
http://www.aspfaq.com/show.asp?id=2467
--
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: Top 10 items?
am 08.03.2006 09:46:00 von Mike Brind
Bob Barrows [MVP] wrote:
> TRB_NV wrote:
> > For the heck of it and because it's a little more elegant, I used the
> > TOP keyword. Thanks for your help. It's always nice to produce neat
> > and clean code.
>
> In that case, you might want to look into using GetRows instead of looping
> through recordsets:
> http://www.aspfaq.com/show.asp?id=2467
>
And using the execute method of the connection object to create a
recordset:
http://www.aspfaq.com/show.asp?id=2191
:-)
--
Mike Brind
Re: Top 10 items?
am 08.03.2006 13:18:33 von reb01501
Mike Brind wrote:
> Bob Barrows [MVP] wrote:
>> TRB_NV wrote:
>>> For the heck of it and because it's a little more elegant, I used
>>> the TOP keyword. Thanks for your help. It's always nice to
>>> produce neat and clean code.
>>
>> In that case, you might want to look into using GetRows instead of
>> looping through recordsets:
>> http://www.aspfaq.com/show.asp?id=2467
>>
>
>
> And using the execute method of the connection object to create a
> recordset:
> http://www.aspfaq.com/show.asp?id=2191
>
Actually, I consider that to be somewhat irrelevant. The same exact things
occur behind the scenes (perhaps in a somewhat different order, but the
outcome is the same) whether one uses:
1)
Set MyRS = Server.CreateObject("ADODB.Recordset")
MyRS.Open MySQL, MyConn,,,1
or
2)
Set MyRS = MyConn.Execute(MySQL,,1)
Let's compare. In version 1:
1-a recordset object is instantiated
2-its Open method is called without setting the recordset's cursorlocation
property, causing it to remain set to the default (adUseServer, unless the
connection object used to open the recordset had its cursorlocation property
previously set to adUseClient)
3-Since no arguments were supplied for those parameters in the Open
statement, the recordset's cursortype and locktype properties remain set to
the default (this may depend on the OLE DB provider being used)
4-a Command object is instantiated
5-the Command object has its ActiveConnection property set to MyConn, its
CommandText property set to MySQL, and its CommandType property set to 1
(adCmdText).
6-the Command is executed, and the results of the execution are marshaled
into MyRS
In version 2:
1-the connection's Execute method is called
2-a Command object is instantiated
3-the Command object has its ActiveConnection property set to MyConn, its
CommandText property set to MySQL, and its CommandType property set to 1
(adCmdText).
4-the Command object is executed, and a recordset object with default
properties is created to receive the results
5-the recordset object in memory is assigned to MyRS
More important is knowing what type of cursor one is opening, as well as the
consequences of using that cursor type. E.G., some people fail to realize
the consequences of step 5 in version 2, instantiating their own recordset
object, assigning a bunch of non-default properties to the recordset,
calling Execute, and wondering why the resulting recordset does not have the
properties that were assigned to it before Execute was called.
If one wants to be in control of cursortype, etc., one is better off using
the Open method. Sure, the connection properties can be set, but this means
that all recordsets resulting from that connection will have those property
values.
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"