This is my code inside my button Login Click. I would like to know How can I retrieve records from the database from the user that is currently logged in from any of the web forms that proceed the login form or what command do I insert into a select statement to be able to select the username of the current logged n user.
protected void btnLogin_Click(object sender, EventArgs e)
{
var CS = ConfigurationManager.ConnectionStrings["TupperwareDemAppConnString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
var cmd = new SqlCommand(@"SELECT * FROM [USER] WHERE userName= @txtUserName AND userPassword= @txtuserPassword ", con);
cmd.Parameters.Add(new SqlParameter("@txtUserName", txtUsername.Text));
cmd.Parameters.Add(new SqlParameter("@txtuserPassword", txtPassword.Text));
con.Open();
var sda = new SqlDataAdapter(cmd);
var dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count != 0)
{
if (CheckBox1.Checked)
{
Response.Cookies["UName"].Value = txtUsername.Text;
Response.Cookies["Pword"].Value = txtPassword.Text;
Response.Cookies["UName"].Expires = DateTime.Now.AddDays(15);
Response.Cookies["PWord"].Expires = DateTime.Now.AddDays(15);
}
else
{
Response.Cookies["UName"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["PWord"].Expires = DateTime.Now.AddDays(-1);
}
}
}
}