This project is read-only.

Get-SqlData returns System.Object

Feb 16, 2009 at 4:20 PM

    I'm quite new to Powershell so maybe I'm doing something silly, however I was under the impression that Get-SqlData returned an ADO.NET Data Table but when I run it against SQL Server 2008 or 2005 I get a System.Object not System.Data.DataTable.

    Is there something I'm missing?

    I'm running Powershell Version 1 on Windows XP Professional Service Pack 3 with Version 1.4 Production of SQLPSX.

Any help appreciated.


Feb 16, 2009 at 6:11 PM
Actually its an array of System.Data.DataRow which I incorrectly described as a data table. Thanks for catching the error in documentation, I'll update the docs on the next release. Here are a couple tests using Get-SqlData and SQL Server 2008 built-in cmdlet Invoke-Sqlmd:

$au = get-sqldata 'Z002\SqlExpress' pubs "select * from authors"

$au = invoke-sqlcmd -ServerInstance 'Z002\SqlExpress' -Database 'pubs' -Query "Select * from authors"

The output of both the function Get-SqlData and Invoke-Sqlcmd is same:


IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Piped through Get-Member you see the array elements are in fact System.Data.DataRow:

553> $au |  Get-Member

   TypeName: System.Data.DataRow