Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
How i can retrieve the last row have been added to the database using FormView or Gridview
Posted

1 solution

check this article How to populate DataGridView, GridView with SQL statement in C#[^]

to get the last row of a table, I found I could do it like this: -

SQL
select * from articles order by artid desc limit 1;

It basically lists all the rows in decreasing artid order, and only select the first 1 (which is the last row in the table as it's reversed). To get the second from last: -


SQL
select * from articles order by artid desc limit 1,1;

when limit is given two params, it uses the first number as an offset, and the second number as the number of rows to get. If you wanted you could get all last 8 rows by saying .....limit 0,8.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900