从sql查询函数返回数组

时间:2015-11-11 09:30:51

标签: sql arrays powershell

我正在尝试从查询sql表的函数返回一个数组。 一切都好,但仅限于数组的元素不止一个。如果数组仅由一个元素组成,则该函数不返回类型数组而是​​返回类型字符串。我是powershell的新手,很困惑...... 我的功能在这里:

Function test2{
$query = @"
SELECT DfsTgtPath 
FROM DfsData_v2 WHERE TgtSrvName = 'compname' AND DfsTgtPath LIKE  
'%string%' ORDER BY DfsTgtPath"@
$connection = new-object system.data.sqlclient.sqlconnection("server=SQLSERV;database=DB;trusted_connect>i on=true;" ) 
$adapter = new-object system.data.sqlclient.sqldataadapter ($query,$connection)
$table = new-object system.data.datatable
$recs = $adapter.Fill($table)
$aDfsTgtPath = @($table | select -ExpandProperty DfsTgtPath)
return @($aDfsTgtPath)
}

$result = test2

我希望$ result作为一个包含一个单独字符串元素的数组,但它似乎不是一个数组,而是System.String类型。

0 个答案:

没有答案
相关问题