How do i select UserName from table account and also select department in Department table and pass both to session on login
Is it possible to select UserName from account table and department from Department table while logging and pass it to session
this is my login code where i only passed UserName to session
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
int UserID;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Validate_User5"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
Session["UserName"] = ctlLogin.UserName;
Session["Name"] = ctlLogin.UserName;
// cmd.Parameters.AddWithValue("@Email", ctlLogin.UserName);
cmd.Parameters.AddWithValue("@UserName", ctlLogin.UserName);
cmd.Parameters.AddWithValue("@Password", (ctlLogin.Password));
// cmd.Parameters.AddWithValue("@Phone", ctlLogin.UserName);
cmd.Connection = con;
con.Open();
UserID = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
switch (UserID)
{
case -1:
ctlLogin.FailureText = "Username or password not correct.";
break;
case -2:
ctlLogin.FailureText = "Account has not been activated.";
break;
case -3:
ctlLogin.FailureText = "Your Password.";
break;
default:
Response.Redirect("~/LandingPage.aspx");
break;
}
}
}
}
}
But now i want to pass also department from Department table so that i can use department session to fetch record on a particular page
TABLE Account
--------------------------
====================================================================================================================
UserName |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Steve1 |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TABLE Department table
--------------------------
====================================================================================================================
UserName | Department
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Steve1 | Sales
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------