I am new to ASP.net. I have been taking values from Session[] variables and storing into Session variables, but I am not able to store values obtained after running a SELECT query in ASP.net.
Example: Select Fname, Mname , Lname from employee
After running this query I want to store the value of "Fname", "Mname" and "Lname" in 3 separate session variables so that I can retrieve in all the further pages from these variables.
Heres my code to check whether its a valid user or not. What I want is, once it is authenticated, all its data be fetched from database and get store in the session variables so that they can be used on all pages directly.
`protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["UserDetailsForGridViewConnectionString"].ConnectionString); conn.Open();
string loginCheck = " select count(*) from USERDETAILS where EMPLOYEEID='" + TextBox1.Text + "' and PASSWORD='" + TextBox2.Text + "'";
SqlCommand myloginCheckcmd = new SqlCommand(loginCheck, conn);
int temp = Convert.ToInt32(myloginCheckcmd.ExecuteScalar().ToString());
if (temp == 1)
{
LoginStatus.Text = "SUCCESS !!";
temp = 0;
Session["EMPLOYEEID_sn"] = TextBox1.Text;
Session["IsLogin"] = "yesLogin";
//TextBox1.Text = "";
Response.Redirect("~/CustomPages/Lecturer_PersonalDetailsPage.aspx");
conn.Close();
}
else
{
LoginStatus.Text = "Invalid Username/Password";
temp = 0;
TextBox1.Text = "";
conn.Close();
}
}`