Session not working for EmployeeDepartmentID and only works with EmployeeLevelID when using logical operators

  • Thread starter Thread starter Angelina2331
  • Start date Start date
A

Angelina2331

Guest
was wondering if I could get some help here. There are two important things: 1. EmployeeLevelID (CEO with EmployeeLevelID 1, VP with EmployeeLevelID 2, Head with EmployeeLevelID 3, and RegularEmployee with EmployeeLevelID 4), and I also have EmployeeDepartmentID as well, which corresponds to the departments of each employee. Each employee has their own department. Basically, what I'm trying to achieve here is if the person logged in is BOTH a VP (EmployeeLevelID 2) and has a Department with EmployeeDepartmentID 1, it will show all the employees with EmployeeDepartmentID's of 1-6
When I run this code, it works perfectly, only it does not take into account the department, only the level:

if (((string)Session["EmployeeLevelID"] == "2"))
{
using (SqlCommand cmd = new SqlCommand(query1, con))
{

cmd.Parameters.AddWithValue("@EmployeeID", Session["EmployeeID"].ToString());

using (SqlDataReader dr = cmd.ExecuteReader())
{
lvEmployees.DataSource = dr;
lvEmployees.DataBind();
}
}
}

But when I run this, no employees start to show: (Once I start to include EmployeeDepartmentID, employees just disappear and I don't know why. :/ How do I go about this? I've put the new code as bold and underlined below:



if ((((string)Session["EmployeeLevelID"] == "2")) && ((string)Session["EmployeeDepartmentID"] == "1"))
{
using (SqlCommand cmd = new SqlCommand(query1, con))
{

cmd.Parameters.AddWithValue("@EmployeeID", Session["EmployeeID"].ToString());

using (SqlDataReader dr = cmd.ExecuteReader())
{
lvEmployees.DataSource = dr;
lvEmployees.DataBind();
}
}
}

Any help would be awesome.... it's been 2 days and I was completely stuck on as to how I can do this. :/

Continue reading...
 
Back
Top