|
System.Data.Common.DbDataReader and change in type Hi everyone,
I'm truying to create a small function to execute a query against an
SQL server. After which I try using the function ($conn is a working,
already initialized):
However, the type of $data isn't [System.Data.Common.DbDataReader]
anymore, it has become [System.Array]
Is there any way to avoid this change in type, and why does it occur?
function Query-SQL {
Param ($query, $conn)
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlCmd.CommandText = $query
$sqlCmd.Connection = $conn
$Rset = $sqlCmd.ExecuteReader()
$Rset.gettype() # <-- [System.Array]
Return $Rset
}
$data = Query-SQL "SELECT * from master..sysdatabases" $conn
$data.gettype() # <--[System.Data.Common.DbDataReader]
Regards,
Jakob Bindslet, Denmark |