Making sure that the only employees that I can view under my department are the ones UNDER my department, and not ALL employees in all departments

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

Angelina2331

Guest
Hi, I have a question. Let's say for example:


Employee 1 has:

EmployeeID of 1, EmployeeLevelID of 1, and EmployeeDepartmentID of 3

Employee 2 has:

EmployeeID of 2, EmployeeLevelID of 2, and EmployeeDepartmentID of 3


If I am logged in as Employee 1, how do I do the code which says that: If EmployeeDepartmentID of Employee 2 is the same as the EmployeeDepartmentID of Employee 1, display first name and last name of Employee 2?


Here is my current code, I know it's wrong because I purposely selected "WHERE EmployeeDepartmentID=3 AND EmployeeLevelID=2". But this would only work for accounts with an EmployeeDepartmentID of 3. I want to make something that says when I log in, the employees with the same department id as I have will only show up, and not all registered employees (because there are different departments):



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

public partial class DEPARTMENTHEAD_ViewListOfEmployees : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

GetEmployees1();

}
}

void GetEmployees1()
{
using (SqlConnection con = new SqlConnection(Helper.GetConnection()))
{
string query1 = @"SELECT EmployeeID, LastName, FirstName, MiddleName FROM EmployeeTable WHERE EmployeeDepartmentID=3 AND EmployeeLevelID=2";


con.Open();


using (SqlCommand cmd = new SqlCommand(query1, con))
{

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

Continue reading...
 
Back
Top