rapture 134 Posting Whiz in Training

To get the last record in a SQL database you simply type

SELECT TOP 1 * FROM tableName ORDER BY columnWithYourID DESC

or if you just need the id then


SELECT TOP 1 (columnWithYourID ) FROM tableName ORDER BY columnWithYourID DESC

This will return the last record in the column you want from the table you are looking for. How to translate that into C# without using SQL I do not know.

sknake commented: no. That is unsafe as it creates a race condition. -1