使用Powershell v1.0,如何将DataSet中的数据添加到字符串中?

时间:2015-04-02 15:43:20

标签: powershell-v1.0

我想将DataSet对象中的数据添加到现有字符串中。

当前代码:

$Dataset.Tables[0] | foreach {
              $_
 }

返回:
enter image description here

但是当我尝试将这些数据添加到字符串中时,我什么都没有添加。

$emailBody = "ALERT!: The following errors were found - `n"    
$Dataset.Tables[0] | foreach {

                $emailBody += <I don't know what to put here>

            }

如何在DataSet中获取结果并将它们添加到此字符串?

1 个答案:

答案 0 :(得分:0)

参考链接: How to loop through a dataset in Powershell

在改变我构建问题的方式时,我在相关帖子中找到了我的问题的答案,可以通过上面的链接访问。

<强>解答:

$emailBody = "ALERT!: The following errors were found - `n" 
foreach ($Row in $Dataset.Tables[0].Rows)
            {
                $emailBody +=  "$($Row[0]) `n"
            }

<强>结果:

它列出了从数据库中提取的数据,并将其添加到DataSet对象中。