Re: Retieve last record in the DB???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

SELECT TOP 1 * FROM Town ORDER BY TownID DESC


"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E3FAFFFA-CBD1-499B-9EA8-C31DDEA80C85@xxxxxxxxxxxxxxxx
> 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


.