title: Exception calling "ExecuteNonQuery" with "0" argument(s): "The parameterized query
body: <p>I am using ADO connection to Insert data into MS SQL Server 2016 from a PowerShell output from an API.</p>
  
  <p>My script below:</p>
  
  <pre><code>$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=XYZ; Initial Catalog=Z; Integrated Security=SSPI")
  $conn.Open()  
  $cmd = $conn.CreateCommand() 
  
  $JSONResult |Select id,surname,managingDeanery
  foreach($obj in $JSONResult) {  
      $Command = New-Object System.Data.SQLClient.SQLCommand
      $Command.Connection = $dbConnection
      $cmd.CommandText = "INSERT Client (id,surname,managingDeanery) VALUES (@id,@surname,@managingDeanery)"  
      $cmd.Parameters.AddWithValue("@id",$obj.id);
      $cmd.Parameters.AddWithValue("@surname",$obj.surname); 
      $cmd.Parameters.AddWithValue("@managingDeanery",$obj.managingDeanery);           
      $cmd.ExecuteNonQuery()   
      $cmd.Parameters.clear();  
  }  
  $conn.Close()
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code> Exception calling "ExecuteNonQuery" with "0" argument(s): "The parameterized query '(@id int,@surname nvarchar(9),@managingDeanery nvarchar(4000))IN' 
       expects the parameter '@managingDeanery', which was not supplied."
       At line:30 char:5
       +     $cmd.ExecuteNonQuery()
       +     ~~~~~~~~~~~~~~~~~~~~~~
           + CategoryInfo          : NotSpecified: (:) [], 
             MethodInvocationException
           + FullyQualifiedErrorId : SqlException 
  </code></pre>
  
  <p>I have tried using: </p>
  
  <pre><code>$cmd.Parameters.AddWithValue("@managingDeanery",'$obj.DBNull.Value'); 
  </code></pre>
  
  <p>But this makes all the empty fields and non empty fields as <code>$obj.DBNull.Value</code> in the <code>managingDeanery</code> column which is incorrect. Not all the data in the column is empty.</p>