Click here to Skip to main content
15,886,802 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello Guru's

Thanks so much for earlier help to achieve AD .
At present am having trouble to include AD function in my code.
Hope some will guide me in the right direction
what am trying to do is get the value from webservice and check with AD and retrieve the name and update the database.

Here is my code

public ArrayList GetEmployeesFromService()
        {

       DirectoryEntry entry = new DirectoryEntry("GC://Test", "Test\\Test", "Ld@Test", AuthenticationTypes.Secure);

            System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry);

            ArrayList resultList = new ArrayList(); 
          
            foreach (EmployeeExport  item in svcWrapper.GetEmployees)
            {
            
                resultList.Add(item.Department);
                
                System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(@"Data Source=SYDTESTSVR05;Initial Catalog=DLAPGateway_DEV;Integrated Security=SSPI");
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                cmd.CommandType = System.Data.CommandType.Text;

            
                search.Filter = "(otherpager=" + item.EmployeeNumber + ")";
                

                
                 SearchResult result = search.FindOne();
                 ResultPropertyCollection fields = result.Properties;
                 foreach (String ldapField in fields.PropertyNames)
                {

                    if (ldapField == "name")
                        string name;
                        name =ldapField.ToString().Trim();
                }

            

                cmd.CommandText = "INSERT Person (EmployeeNo,NamePrefix,FirstName, MiddleName, LastName, NameSuffix,Contractor,HighestEducationalLevel, BirthDate, Gender ) VALUES("
                                                   + item.EmployeeNumber + ","
                                                   + "'" + item.Title + "'" + ","
                                                   + "'" + item.PreferredName + "'" + ","
                                                  //+ "'" + item.MiddleName + "'" + ","

                                                   + "'" + item.MiddleName.Replace("'", "''") + "'" + ","
                                                    + "'" + item.Surname.Replace("'", "''") + "'" + ","
                                                    + "'" + item.Suffix + "'" + ","
                                                    + "'" + item.PayPoint + "'" + ","
                                                    + "'" + item.HighestEducationLevel + "'" + ","
                                                    + "'" + item.BirthDate + "'" + ","
                                                    + "'" + item.Sex + "'" + ")";


                
                cmd.Connection = sqlConnection1;
                sqlConnection1.Open();
                cmd.ExecuteNonQuery();
                sqlConnection1.Close();

                
            }

            return resultList;  
        }
Posted
Updated 7-Mar-11 19:57pm
v2
Comments
Pravin Patil, Mumbai 8-Mar-11 1:58am    
Added the code block..
Ryan Zahra 8-Mar-11 4:18am    
Can you give the link to the previous question to get a better idea of the problem?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900