2013-03-08 79 views
0

未在datagridview中獲取信息。 如果我在多文本嘗試它的罰款,但不是在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(); 
+0

你確定你想轉換爲字符作爲你的GridView的數據源的列表的字符串? – rikitikitik 2013-03-08 03:28:17

+0

'string.ToList()'返回'列表'。你期望看到什麼? – 2013-03-08 03:30:38

回答

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(); 
+0

我收到錯誤{「服務器不可操作。\ r \ n」}在foreach(SearchResult sResultSet Dsearch.FindAll()) – user113784 2013-03-08 04:22:57

+0

Thx,我沒有正確,但沒有結果出來 – user113784 2013-03-08 04:29:51

+0

我有調試,發現沒有值傳遞在任何人都可以爲什麼在代碼中出現錯誤 – user113784 2013-03-08 05:11:37