在PowerShell中执行SQL代码失败。我需要转换以下SQL,并在PowerShell中调用它。
SQL
USE [Test]
GO
DECLARE @return_value INT
EXEC @return_value = [dbo].[WB_Open] @Description = N'WTS Entrance'
SELECT 'Return Value' = @return_value
PowerShell($ SQLServer和$ SQLDBName通过函数传递)
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$SQLServer;Database=$SQLDBName;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure
$SqlCmd.Parameters.AddWithValue("@return_value", 1) | Out-Null #not sure about this
$SqlCmd.Parameters.AddWithValue("@description", 'WTS Entrance') | Out-Null
$SqlCmd.CommandText = "WB_Open"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
我没有运气就尝试了以下内容(对此没有经验),我敢肯定这是我的语法,但是我已经花了很多时间试图弄清楚这一点-在这里非常感谢您的帮助!
您的结果在$ DataSet.Tables [0]]中>