Hallo zusammen!
Ich programmiere mit VB.NET 2003!
Ich möchte gerne Infos(user von einer Active Directory) zum Datagrid übergeben bzw. ich versuche es...er gibt kein Fehler aus - mein Fenster bleibt schließlich aber nur weiss.
Hat jemand eine ahnung wie ich das machen könnte? (DataGrid1.DataSource = ds)
Danke im Voraus!
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Imports System
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.DirectoryServices
 
Namespace WebApplication1
    Public Class WebForm2
        Inherits System.Web.UI.Page
        Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
        Public de As DirectoryEntry
        Protected WithEvents dv As System.Data.DataView
        Public ds As DataSet
 
        Function CreateDataSource() As ICollection
 
            Dim dt As New DataTable
 
            Dim dr As DataRow
 
            dt.Columns.Add(New DataColumn("CommonName", GetType(String)))
            dt.Columns.Add(New DataColumn("Email Address", GetType(String)))
 
 
            Dim de As New DirectoryServices.DirectoryEntry("LDAP://blndc003:389/OU=BLN,DC=HACH-LANGE,DC=EWQG,DC=COM")
 
            Dim rootSearch As New DirectorySearcher(de)
 
            Dim SearchResult As SearchResult
 
            Dim results As SearchResultCollection
 
            rootSearch.PropertiesToLoad.AddRange(New String() {"cn", "mail"})
 
            rootSearch.Filter = "(&(objectCategory=Person)(objectClass=user))"
 
            results = rootSearch.FindAll
 
            For Each SearchResult In results
 
                Try
 
                    dr = dt.NewRow()
 
                    If SearchResult.Properties.Contains("CN") Then
                        dr(0) = SearchResult.Properties("CN").Item(0)
 
                    End If
 
                    If SearchResult.Properties.Contains("mail") Then
                        dr(1) = SearchResult.Properties("mail").Item(0)
 
                    Else
 
                        dr(1) = "No E-Mail Address"
 
                    End If
 
 
                    dt.Rows.Add(dr)
 
                Catch ex As Exception
 
                    Dim debug As String = ex.Message
 
                End Try
 
            Next
 
            Dim dv As New DataView(dt)
 
            Return dv
 
        End Function
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If Not IsPostBack Then
                DataGrid1.DataSource = ds
                DataGrid1.DataBind()
            End If
        End Sub