Retieve last record in the DB???

G

Guest

Simple question...

I want to retrive the last record in the database if the value of id is
nothing!

Can someone please help!

Thanks

....CODE...
Dim objImpCnt As SqlParameter
If objImpCnt Is Nothing Then
objImpCnt = cmd.Parameters.Add("@newsID", SqlDbType.Int)
objImpCnt.Direction = ParameterDirection.Input
objImpCnt.Value = id
Else
objImpCnt.Value = 'Last Record in the db
End If
 
G

Guest

Hi Tim,

Duinno about the code for the way ur doing it, but the SQL logic would be
something like "SELECT TOP 1 ... ORDER BY newsid DESC"

HTH a bit :)

Cheers


Dan
 
J

Josh

Assuming you have an Identity key on the table and the table is called
Town...

SELECT TOP 1 * FROM Town ORDER BY TownID DESC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top