Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Passingavariabletoaquery

I have the below code, where I search active directory for a loginname and display user's telephone number. I get the user input from a form "TextBox1.text" which I have labelled as a variable xpid. I need to pass the variable in line 15. However I am not able to pass the variable in "anr" Can you please let me how to pass the variable in line 15. I don't know know what to write there in "whattowritehere"

Imports System.DirectoryServices
Imports System

Public Class Form1
    Dim xpid As String
    Dim username As String
    Dim country As String
    Dim tel As Integer
    Dim rootEntry _
        As New DirectoryEntry("GC://abc.de.fg.com")
    Dim searcher As New DirectorySearcher(rootEntry)

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        xpid = TextBox1.Text

        searcher.PropertiesToLoad.Add("l")
        searcher.PropertiesToLoad.Add("telephoneNumber")

        searcher.Filter = "(&(anr=whattowritehere)(objectCategory=person))"

        Dim results As SearchResultCollection
        results = searcher.FindAll()

        Dim result As SearchResult
        For Each result In results
                MessageBox.Show(result.Properties("telephoneNumber")(0))
        Next
    End Sub
End Class

Comments