Click here to Skip to main content
16,004,540 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi to all
can u pls send the code how to store login and logout time in database using sessions can u solve dis

below
snippet

SqlConnection con = new SqlConnection("Data Source=suhels;Initial Catalog=suhel1;User ID=sa;Password=abc");
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Login_Click(object sender, EventArgs e)
{
con.Open();

string q = "select Count(*) from memebers where username='" + TextBox1.Text + "' AND password ='" + TextBox2.Text + "'";

SqlCommand comm = new SqlCommand(q, con);
int result = (int)comm.ExecuteScalar();

if (result > 0)
{

String s = "insert into Logins('"+TextBox1.Text+"',DateTime.Now

cmd.Parameters.AddWithValue("@username",TextBox1.Text);
cmd.Parameters.AddWithValue("@logintime", DateTime.Now.ToShortDateString());
cmd.ExecuteNonQuery();
Session["User"] = TextBox1.Text.ToString();

cmd = new SqlCommand(s, con);
int r = cmd.ExecuteNonQuery();
}
Posted
Updated 22-Jan-12 20:18pm
v4

You can use follwing events for storing dateTime in database
on LoginButton click - you can store DateTime.Now.ToString("MM/dd/yyyy hh:MM:ss")
on logout link - before Application.Exit store datetime

this is simple, what an issue ?
 
Share this answer
 
Comments
kingsa 23-Jan-12 2:05am    
can u send me code using sessions
kingsa 23-Jan-12 2:06am    
when its validate the login data table stores login time send me code
kingsa 23-Jan-12 2:07am    
using sessions only
There is one link descibing what you really want....
Go for it. It is a very good article.

Tracking users login/logout times on your site[^]
 
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