record movement/ display total

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using ExecuteScalar with my SQL statement with an Order BY XXXXXX DESC to
get the last record. I wish there was a better way to retrieve it, like ADO
with movelast. Does anyone know of a better way?

Also, what if I just want the most recent 5 records, based on date field?
TOP won't yield me my desired results, will it?
Any ideas?

Thanx.
 
Top "would" yield you the most recent results if your order
by is desc on the date column.

Why would you think it doesn't? Perhaps you should post
your SQL code.
 
Thanx, I realized that right after I wrote this. I had TOP % ingrained in my
head for some reason. What do you think about my ExecuteScalar mehtod to get
the last record? Didn't know if there was a better way?

thanx.
 
If you use this in conjunction with the ORDER BY DESC, you
are only returning one record from the database. I can't think of
a faster way short of querying for the highest primary key value
if your primary key column is an identity seed. A query from
the index is likely to be faster than the column referenced in
your order by statement.

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.learncsharp.net/home/listings.aspx
 
thanx.

Robbe Morris said:
If you use this in conjunction with the ORDER BY DESC, you
are only returning one record from the database. I can't think of
a faster way short of querying for the highest primary key value
if your primary key column is an identity seed. A query from
the index is likely to be faster than the column referenced in
your order by statement.

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.learncsharp.net/home/listings.aspx
 
Back
Top