This optional parameter can be used when you're running an ADO
command in a way which normally returns records, but you know
that none will actually be returned. It was introduced in ADO
2, so obviously it won't work if you're running an older version,
but if you are running ADO 2.0 or greater, it's an easy way to
gain some additional performance.
There is a certain level of overhead associated with ADO
preparing to return a recordset. By itself this isn't that
big of a deal, but there are also a number of methods
in ADO which return a recordset object by default. It was
realized that many of these methods were being used in a
manner which resulted in recordsets being generated and
returned without any records.
While this behavior is fine if you happen to run a query
which finds no matching results, it's pretty wasteful
if you're doing an insert
and aren't expecting anything back or are running a stored
procedure and are only looking to get back a return value
instead a recordset. It's this inefficiency from which
AdExecuteNoRecords arose. It tells ADO to not spend the time
to prepare a
recordset for return because we know in advance that there isn't going to be one.
It reduces overhaed and can thus help increase performance.
The constant is included in newer versions of the constant files
as well as in the type library. It's extremely simple to use
and is normally used as a parameter to the Execute method of the
Connection or Command object. Here's a quick example:
cnn.Execute "INSERT INTO table (field_name) VALUES (value)", lngRecsAffected, adCmdText Or adExecuteNoRecords
The above is a line that exectes a SQL text insert
command (adCmdText) which would return the
number of records affected into lngRecsAffected and
tells ADO that there will be no records returned.
It's pretty straight forward, but you'll notice that
we're not assigning the output to a recordset like you
normally do with Execute commands. This is because, as the
parameter says, we know there won't be one returned.
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.