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:
After...
$result = $command.ExecuteReader()
... add the following:
$Table = New-Object System.Data.DataTable
$Table.Load($result)
$Email = $Table.email
Write-Output $Email

Open in new window

0
 
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.

toshi
0
 
dsackerContract ERP Admin/ConsultantCommented:
Actually, the variable $Email contains the value you're looking for.
0
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.