0

未在 datagridview 中获取信息。如果我在多文本框中尝试过它很好但在 datagridview 中没有

public String Accountlocked()
        {
            //DirectoryEntry entry = new DirectoryEntry("LDAP://Mytechnet.com");
            DirectoryEntry entry = new DirectoryEntry("LDAP://User");
            DirectorySearcher Dsearch = new DirectorySearcher(entry);



            Dsearch.Filter = "(&(&(&(&(&(objectCategory=person)(objectClass=user)>>(lockoutTime:1.2.840.113556.1.4.804:=4294967295))))))";


            using (StringWriter sw = new StringWriter())
            {

                foreach (SearchResult sResultSet in Dsearch.FindAll())
                {

                    sw.WriteLine("{0}", (GetProperty(sResultSet, "samaccountname")));
                    sw.WriteLine("{0}", (GetProperty(sResultSet, "name")));

                }
                return sw.ToString();

            }

        }

开启按钮

dataGridView1.DataSource = Accountlocked().ToList();
4

1 回答 1

0
public DataTable Accountlocked()
        {
           //DirectoryEntry entry = new DirectoryEntry("LDAP://Mytechnet.com");
           DirectoryEntry entry = new DirectoryEntry("LDAP://User");
           DirectorySearcher Dsearch = new DirectorySearcher(entry);

           Dsearch.Filter = "(&(&(&(&(&(objectCategory=person)(objectClass=user)>>(lockoutTime:1.2.840.113556.1.4.804:=4294967295))))))";

           DataTable dt = new DataTable();
           dt.Columns.Add("AccountName");
           dt.Columns.Add("Name");
                foreach (SearchResult sResultSet in Dsearch.FindAll())
                {
                   DataRow dr = dt.NewRow();          
                   dr[0] = (GetProperty(sResultSet, "samaccountname"));
                   dr[1] = (GetProperty(sResultSet, "name"));
                   dt.Rows.Add(dr);
                }
                return dt;
            }
        }


dataGridView1.DataSource = Accountlocked();
于 2013-03-08T03:33:03.887 回答