anpalmer Posted October 4, 2004 Posted October 4, 2004 Hi, As each day passes I gain more insight into the functionality of asp.net and also loose some more hair from my temples from pulling at it in frustration. Programming is great! :D Anyhew, I digress, this is an open question to all who know more than me, so nearly all members of this forum! I need to return the last entry posted to a database and display the entry in a pretty fashion for the user. The key piece of data the user needs is the ID (autonumber) for the entry so they can record this somewhere else. Is there a way of returning to the user the last ID number added to the database? I remember reading something somewhere once (sorry for being vauge), which stated that this was possible, if this is the case that would be great. Thanks for any help anyone can give. I am going to get back to pulling at my hair! Thanks Ash Quote
eramgarden Posted October 4, 2004 Posted October 4, 2004 Cant you do a "max"? select max(yourcolumn) from yourtable where.. Quote
bri189a Posted October 4, 2004 Posted October 4, 2004 I think your recalling the @@ID return value; this only works with SQL Server, with MS Access you need to set something up in the RowUpdated (maybe RowUpdating) event. Quote
Moderators Robby Posted October 4, 2004 Moderators Posted October 4, 2004 If this is SQL Server and you're inserting using as stored procedure (Which I strongly recommend) then you can get the id with @@Identity (Return this value from the proc) Quote Visit...Bassic Software
anpalmer Posted October 4, 2004 Author Posted October 4, 2004 Hi, Thanks for the quick reply, I am using SQL Server, can you tell me more about the @@ID feature you mentioned? Thanks Ash Quote
Moderators Robby Posted October 4, 2004 Moderators Posted October 4, 2004 It's @@IDENTITY, you would do something like this in your stored proc.... declare @myID int SET @myID = 0 INSERT INTO myTable ......your columns here.... SET @myID = @@IDENTITY return @myID Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.