Retieve last record in the DB???

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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

Back
Top