Skip to content
Advertisement

Why am I getting System.Data.DataRow here?

Im unsure as to why Im getting this because I have the same code elsewhere and there is no problem.

Thanks for your help.

[System.Collections.ArrayList]$logFileObjects = @()


foreach($confirmation in $confirmationArray){

    $object = [PSCustomObject] @{
    confirmationNumber = $confirmation
    Keycode = getKeycode -confNumber $confirmation
    }

    $logFileObjects.Add($object) | Out-Null


    $object.confirmationNumber + " " +  $object.Keycode
}

Output

0000000091260759 System.Data.DataRow
0000000091308925 System.Data.DataRow
0000000091116609 System.Data.DataRow

Advertisement

Answer

Thanks to @MathiasR.Jessen

Change the getKeyCode function to only return the column value you want rather than the entire row:

return (Invoke-Sqlcmd -ServerInstance myserver -Database mydb -Query $QueryConf).Item('Keycode')
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement