Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Powershell-将System.Data.DataRow解析为字符串_String_Powershell_Datarow - Fatal编程技术网

String Powershell-将System.Data.DataRow解析为字符串

String Powershell-将System.Data.DataRow解析为字符串,string,powershell,datarow,String,Powershell,Datarow,我需要您提供有关如何在powershell中将SQL查询的输出转换为字符串的信息。我目前正在做以下工作 function ExecuteFromScriptRowset($connectionParams, $file) { return (invoke-sqlcmd @connectionParams -inputFile $file -MaxCharLength 8000000) } 我使用上面的函数调用一个.sql文件 SELECT Names FR

我需要您提供有关如何在powershell中将SQL查询的输出转换为字符串的信息。我目前正在做以下工作

function ExecuteFromScriptRowset($connectionParams, $file)
{
     return (invoke-sqlcmd @connectionParams 
             -inputFile $file -MaxCharLength 8000000)
}
我使用上面的函数调用一个.sql文件

SELECT Names FROM tblXXX
下面是我用来调用SQL存储过程的实际powershell代码

$output = ExecuteFromScriptRowset $someDB (Resolve-Path '.\selectXXX.sql')
输出是System.Data.DataRow的数组,我需要将其转换为字符串数组。我目前正在尝试以下不符合预期的方法

$formatOut = @()

for ($i=0; $i -le $output.Length; $i++)
{
    $formatOut = $formatOut + [string]$output[$i]
}
下面是$formatOut的输出,它位于for循环之后,这不是我想要的

$formatOut[0] = System.Data.DataRow
$formatOut[1] = System.Data.DataRow
$formatOut[2] = System.Data.DataRow

请告诉我需要做什么,以便创建$output对象内容的字符串数组,因为默认情况下,
ToString
将输出对象类型,所以您看到的是完全正常的。这符合.NET规范

您可以使用
ItemArray
DataRow
转换为对象数组,然后通过“,”或您喜欢的任何连接方法进行连接,如下所示:

$formatOut = $formatOut + ($output[$i].ItemArray -join ",")