I have successfully read a single returned value but can't quite get multiples.
My query is something like
select value
from table
where a in ('here', 'there').
In SQL Server, I see two rows being returned:
'first'
'second'
My script does the following:
$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()
$rc = $result.Read()
I can't seem to find the right way to see that there are two rows (I assume there are rows rather than columns because this is how it shows in SQL) or what the second value is; I can see the first by executing:
$fnum = $result.hasrows
if ($fnum -eq "True") {
$fname = $result.GetValue(0)
#write-host $fname
} else {
write-host "parm not found"
exit 5
}
So $fname does have a value (first). $result.count shows '1 1' like there are two values. I tried doing a $result.getvalue(1) and tried doing another read and then getvalue. Neither works.
How do I get the second value and how do I see that there are two?
while($result.Read()){...}. You don't make clear what you want to do here.Invoke-DbaQuerycmdlet, which does most of this for you.HasRowsreturns a boolean, meaning the comparison against as string (-eq "True") is questionable, see also: stackoverflow.com/a/78869703/1701026