Click here to Skip to main content
16,021,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to retrive the last login of the user from user login table. What is the query to retrive last logged in date..?
Posted
Updated 15-Jun-13 1:24am
v2
Comments
Mike Meinz 15-Jun-13 7:34am    
What is the design of the "user login" table? What are the column names and their attributes?

Also, the subject says first date but the question says last logged in date. Please be more specific.

1 solution

Assuming that this is a log table of some form, and you store the user ID and login date:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 loginDate FROM myTable WHERE useID = @ID ORDER BY loginDate DESC", con))
        {
        cmd.Parameters.AddWithValue("@ID", userId);
        DateTime lastLogin = (DateTime) cmd.ExecuteScalar();
        }
    }
 
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