Retrieve username and convert to email using LDAP RRS feed

  • Question

  • 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)
                    //search email
                    DirectorySearcher dssearch = new DirectorySearcher(ad);
                    dssearch.Filter = "(sAMAccountName=" + name + ")";
                    SearchResult sresult = dssearch.FindOne();


    Sunday, October 25, 2015 12:22 AM


  • User-698989805 posted

    This surely will help you out. Check the following:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 25, 2015 1:04 AM