i have a command (query) against microsoft sql server, i ask only one value, i have it , how can i recover it ?

Hello ,

i have a code that query a mssql db as follows :

    $query = "SELECT email From Person Where EmployeeID='ESC" + $person.Split(';')[0] +"'"

    $command = $connection.CreateCommand()
    $command.CommandText = $query

    $result = $command.ExecuteReader()

question :
how to recover the email value ??? how should i use $command in order to have one value not a table ?

thank you in advance.
Erwin PombettAsked:
Who is Participating?
dsackerContract ERP Admin/ConsultantCommented:
$result = $command.ExecuteReader()
... add the following:
$Table = New-Object System.Data.DataTable
$Email = $Table.email
Write-Output $Email

Open in new window

Erwin PombettAuthor Commented:
thank you dsacker,

am i forced to create a datatable ?
is it not possible as it 's only one value, get it straight into a simple variable ?

thank you for further help.

dsackerContract ERP Admin/ConsultantCommented:
Actually, the variable $Email contains the value you're looking for.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.