What I want to do is to add items in my comboSubDep wherein it compares what subject the teacher has. For example: if I select Math for my subject only teachers of that subject should appear. But I don't want to compare it directly to a specific subject. I just want it to loop to every subject that the database has. In which the subject is not constant.
con.Open();
cmd = new SqlCommand("SELECT Emp_FName, Emp_LName, T_Subject FROM Employee WHERE Emp_Position = 'Teacher'", con);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string sub = rdr["T_Subject"].ToString();
string fname = rdr["Emp_FName"].ToString();
string lname = rdr["Emp_LName"].ToString();
string fulname = fname + ' ' + lname;
if (ComboSubDep.Text != sub)
{
txtTeacher.Text = "";
txtTeacher.Items.Clear();
}
else
{
txtTeacher.Text = "";
txtTeacher.Items.Clear();
txtTeacher.Items.Add(fulname);
}
}
rdr.Close();
con.Close();