Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all,

I have a table that has entered data.

One of the these columns is the date.

I want to select the last column of data that has been entered.

Can any one help me?
Thanks
Posted
Updated 20-Feb-11 21:53pm
v2
Comments
Prerak Patel 21-Feb-11 2:32am    
select or sort or what?
Albin Abel 21-Feb-11 2:37am    
you have to use IS NOT NULL in where clause for the date column and MAX aggregate on a autoincrement coulmn. Use this as a sub query for the where clause in a main query.
Dalek Dave 21-Feb-11 3:53am    
Edited for Grammar and Readability.

Try:
C#
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand com = new SqlCommand("SELECT * FROM myTable ORDER BY date DESC", con);
SqlDataReader r = com.ExecuteReader();
if (r.Read())
    {
    Console.WriteLine((DateTime) r["date"]);
    }
r.Dispose();
com.Dispose();
con.Dispose();
The "ORDER BY" and "DESC" parts tell it to return the rows in a specific order (in this case by the "date" column) with the newest first.
 
Share this answer
 
Comments
moon2011 21-Feb-11 2:51am    
thanks alot
Dalek Dave 21-Feb-11 3:54am    
Good Call.
there is my soulation

<br />
SELECT TOP 1 *<br />
FROM TableName<br />
ORDER BY date DESC<br />


thanks
 
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