SQL data row behaviour when only one row returned

I am reading data from sql and so my typename is System.data.datarow. When ever the number of rows returned is greater than one then I can use an index to access the row - e.g. $sqlrow[0] will return all the data from the first row.
However, if only one row is returned, $sqlrow[0] refers to the first property or column, not the entire record. Why is that?

PowerShell is not made for developers. It is made for administrators. So it’s designed to make it as easy for the admin as possible. So if there’s only one element it will assume you only want the properties of this single element. But you can force PowerShell to create an array even if there’s only one element. You just have to use the array subexpression operator “@(...)

1 Like