Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Viewing Last Record

Posted 13 Oct 2004 03:43:10
1
has voted
13 Oct 2004 03:43:10 Tommy Ready posted:
hey,

Does anyone know how to pull just the last record inserted into a table? I tired to do the rs.movelast but it didn't work....any ideas?

Dreamweaver MX | Flash 5/MX | Visual Studio 6.0 | Visual Studio .NET

Replies

Replied 13 Oct 2004 16:25:41
13 Oct 2004 16:25:41 Rene Bandsma replied:
In SQL you could do it with:
<pre id=code><font face=courier size=2 id=code>
ORDER BY Id DESC
</font id=code></pre id=code>
Replied 14 Oct 2004 03:27:18
14 Oct 2004 03:27:18 Tommy Ready replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>bandsma - In SQL you could do it with: ORDER BY Id DESC <hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

I've used that but I for some reason I can't pull just that record...I'm getting some code mixed up somewhere. i even tired

"Select TOP 1 * From tbl order by ID DESC"

I can't figure out how to pull the records.



Dreamweaver MX | Flash 5/MX | Visual Studio 6.0 | Visual Studio .NET
Replied 15 Oct 2004 16:03:59
15 Oct 2004 16:03:59 Vince Baker replied:
You need to have a field in the DB that will show the latest record, for example a id number that increments for each record

If your ID field was called Record_ID and your table was called tbl_Mytable your recordset would look like this:

Select *
from tbl_Mytable
order by Record_ID DESC

The record returned will be the highest numbered ID hence the last record entered.

If you do not have an id field you could use a date field...

Regards
Vince

DMX Talkzone Manager

Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)

VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
Replied 16 Oct 2004 08:49:05
16 Oct 2004 08:49:05 Tommy Ready replied:
I've done that an I still get an error.....ok so I use the sql statment:

"selec t * from table order by ID DESC"

then to pull the record:

&lt;% rs("field" %&gt;

???? I have no idea...totally lost when it comes to pulling the one record...

Dreamweaver MX | Flash 5/MX | Visual Studio 6.0 | Visual Studio .NET
Replied 21 Oct 2004 10:45:30
21 Oct 2004 10:45:30 Vince Baker replied:
If the counter is not displaying change your code to:

&lt;%=rs("field"%&gt;

Regards
Vince

DMX Talkzone Manager

Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)

VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
Replied 25 Oct 2004 16:56:46
25 Oct 2004 16:56:46 Lee Diggins replied:
Hi Tommy

The 'select' statement example given above, will in fact give the last inserted record, but it's not guaranteed to get the last record that you inserted, unless you're the only user of the system. You need to get back the @@IDENTITY value, not sure your DB will support that, what DB are you using?

Digga

Sharing Knowledge Saves Valuable Time!!!

Reply to this topic