Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to retrieve the latest record from database, what should I do?

C#
SqlConnection con = new SqlConnection(conStr);
            con.Open();

            SqlCommand cmdReserveID = new SqlCommand("SELECT ReserveID From Reservation", con);
            SqlDataReader rdr = cmdReserveID.ExecuteReader();

            rdr.Read();
            Label2.Text = rdr["ReserveID"].ToString();
            con.Close();
Posted
Updated 3-Aug-14 19:48pm
v3
Comments
Mike Meinz 2-Aug-14 9:53am    
To give a proper answer, it is necessary to know why you need to know the ReserveID of the last row in the database table?
Kishor Deshpande 4-Aug-14 1:47am    
Why you need the last row?

1 solution

Try below query.This should work for you :-)

SQL
SELECT TOP 1 ReserveID FROM Reservation ORDER BY ReserveID DESC


I assumed your ReserveID column contains unique values
 
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