User-1070219618 posted
Hi, I am trying to use the query to retrieve the username and check the teacher's email address from active directory and send to the teachers (teachers are more than 1).
The project flow is the student submit the form will notified the teachers.
User table: Id, username, role. (Student role =1, Teacher role=0)
I had tried the code as follow:
public void checkuser()
{
using (SqlConnection con = new SqlConnection(constr))
{
//retrieve username from table
SqlDataAdapter adap = new SqlDataAdapter("SELECT username FROM Users WHERE role = 0", con);
DataSet dt = new DataSet();
adap.Fill(dt, "username");
List<string> name = new List<string>();
foreach (DataRow row in dt.Tables["username"].Rows)
{
name.Add(row["username"].ToString());
}
//search email
DirectorySearcher dssearch = new DirectorySearcher(ad);
dssearch.Filter = "(sAMAccountName=" + name + ")";
SearchResult sresult = dssearch.FindOne();
dssearch.PropertiesToLoad.Add("mail");
}
}
Thanks.