我在PowerShell脚本中有以下代码:
$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.DatabaseName = "AdventureWorks2012"
$reader = $conn.ExecuteReader("SELECT Name, CostRate FROM Production.Location")
while ($reader.Read())
{
$name = $reader.GetValue(0);
$cRate = $reader.GetValue(1);
Write-Host $name,"(",$cRate,")"
}
$reader.Close()
如何在while循环中执行另一个select查询?
答案 0 :(得分:-1)
您应该打开与启用MARS的连接,以便在同一连接中打开另一个datareader。看看这篇文章,描述如何在C#中做到这一点,你可以轻松地将它改编为ps: http://www.mindfiresolutions.com/Using-MARS-technique-in-CNET-20-720.php