Tiger Singh

Tiger Singh

  • NA
  • 61
  • 11.1k

Login & logout Time Tracker for Web App !!

Sep 18 2017 8:24 AM
Hi There,
 
I have attached the exisitng code of my login page. an intent is to capture the login details who logged in and the time of log out.
 
The code is working fine till the login purpose but inserting to capture the history not working.
 
Pls help me here insert into is not working !! 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace Oracle_Erp
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = "Data Source=csfsb-sql02;Initial Catalog=xxx_PROD;Integrated Security=True;";
SqlConnection connection = new SqlConnection(connectionString);
try{
string uid = TextBox_UserName.Text;
connection.Open();
string qry = "select USERNAME from USERDETAILS where USERNAME ='" + uid + "' ";
SqlCommand cmd = new SqlCommand(qry, connection);
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.Read())
{
qry = "insert into USERDETAILS_login_Info_History(username,login_time) values('" + uid + "',getdate())";
SqlCommand cmd = new SqlCommand(qry, connection);
LB2.Text = "Login Sucess......!!";
{
Response.Redirect("ListDataExtractForm.aspx");
}
}
else
{
LB2.Text = "CEC Id is not Registered or may typed incorrectly. Please register your CED ID by emailing to xxx along with your manager approval !!";
}
connection.Close();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
 
 
 

Attachment: Login_TimeTracker.zip