How to pass the parameter in SQL query from PowerShell

Posted by Zshava on Stack Overflow See other posts from Stack Overflow or by Zshava
Published on 2010-02-15T15:03:22Z Indexed on 2010/03/30 14:03 UTC
Read the original article Hit count: 372

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about parameters