Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011

    Unanswered: Capture logout time

    I need to capture the logout time and login time. I can capture the login time already but I cannot capture the logout time. I would appreciate all the help that you had given me. Thank you. My logout time and login time need to be on the same entry.
    This is the coding in the logout button:

    protected void logoutButton_Click(object sender, EventArgs e)
                SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
                cmd.Parameters.AddWithValue("@MemberID", Session["MemberID"]);
    I also need to do in global.asax. And this is the coding:
    protected void Session_End(object sender, EventArgs e)
                if (Session["MemberId"] != null)
                //string emailaddress = (string)Session["emailaddress"];
            }protected Boolean UpdateLoggedInUsersLogoutTime(int MemberID)
                SqlConnection connection = null;
                SqlCommand command = null;
                Boolean successFlag = false;
                    string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                    connection = new SqlConnection(connectionString);
                    //retrieve the logid 
                    string connectionString1 = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                    connection = new SqlConnection(connectionString1);
                    //prepare sql statements
                    //string sql = "SELECT * from LoggedInUsers where emailaddress='" + emailaddress + "' And Password='" + password + "'";
                    //command = new SqlCommand(sql, connection);
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    DataTable dt = new DataTable();
                    if (dt.Rows.Count > 0)
                    /* add value to Session */
                    Session["LogId"] = dt.Rows[0]["LogId"].ToString();
                    SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
                    cmd.Parameters.AddWithValue("@MemberID", MemberID);
                    //pass the session 
                    int logid = (int)Session["MemberId"];
                    DateTime dateTime = DateTime.Now;
                    string s = dateTime.ToString();   
                    //update record based on logid
                    SqlCommand cmd1 = new SqlCommand("UPDATE LoggedInUsers set LogoutTime = '" + s + "' Where MemberID = @MemberID");
                    //prepare sql statements
                    string sql1 = "UPDATE  LoggedInUsers set LogoutTime= '" + s + "' where emailaddress=@EmailAddress";
                    //Response.Write(sql + "<br />");
                    //command = new SqlCommand(cmd1, connection);
                    command.Parameters.AddWithValue("@LogoutTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    command.Parameters.AddWithValue("MemberID", MemberID);
                    int rowCount = command.ExecuteNonQuery();
                    //if (rowCount != 0)
                    if (rowCount == 1)
                        successFlag = true;
                        //Response.Write("Operation success.<br/>");
                        //Response.Write("Operation failed<br/>");
                    catch (Exception ex)
                    //Response.Write("Error:" + ex.Message);
                    //cleanup object
                    if (connection != null)
                    return successFlag;

  2. #2
    Join Date
    Nov 2011
    Houston, TX

    Post Greetings and Salutations

    Hi there Fairy,

    Figured I'd give you a bump and muse a bit.

    This may sound like an incredibly obvious question, but have you by chance stepped through your code in the debugger to maybe find out where exactly things are going awry?

    Now, I'm not the most experienced programmer on here by any stretch of the imagination, but maybe I can ask you some questions that'll help you find your answer. If it's the logout value you're going for, and you're not able to get your hands on that, what exactly are you getting your hands on?

    Are you getting data, but not the data you want, or is your code producing an error that's ending up in the catch statement down there?

    I'm sure a probably haven't helped but... ^^;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts