I have this code in PowerShell, that executes SQL query for UPDATE table:
$Connection=new-object data.sqlclient.sqlconnection "server=server;database=mydb;trusted_connection=true;"
$Connection.open()
For( $i = 0; $i -le $ActID.Length; $i ++ ){
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.Connection = $Connection
$cmd.CommandText =
"
update Table
set Note = @PATH
"
$cmd.Parameters.Add("@PATH", $ActID[$i].Values) | Out-Null
$cmd.ExecuteNonQuery()
}
I try to update table with variable defined in this string:
$cmd.Parameters.Add("@PATH", $ActID[$i].Values) | Out-Null
But when i try to execute script, error log says that there is no value passed in $ActID[$i]
Is there other methods to pass parameters (variables) in powershell queries?