For last record :
1.
See This[
^] (the answer is below the advertisements at this link, you will have to scroll a lot).
2.
See This[
^]
To handle the error, if table has no records:
Its just on the top of my head, i cant check it at present, so syntax error may be there:
if(tablename.Records.Count >0)
{
}
OR
See this[
^]
BTW, some googling by you may have saved your and mine lots of time.
(Please accept answer or provide votes if I was helpful)
Anurag