pipeline stopped error when closing out-gridview

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: pipeline stopped error when closing out-gridview

Post by jvierra »

Your function is not well formed and would work better this way as it will return a useful object that is complete, empty or null.
  1. function Exec-Sproc{
  2.     param(
  3.         [System.Data.SqlClient.SqlConnection]$Conn,
  4.         $Sproc,
  5.         [hashtable]$Parameters
  6.     )
  7.     Try{
  8.         $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  9.         $SqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure
  10.         $SqlCmd.CommandTimeout = $script:SqlCommandTimeOut;
  11.         if ($Conn.State -ne 'Open') { $Conn.open(); }
  12.    
  13.         $ build the comamnd
  14.         $cmd = $Conn.CreateCommand()
  15.         $cmd.CommandText = $Sproc
  16.         foreach ($p in $Parameters.Keys) {
  17.             [Void]$cmd.Parameters.AddWithValue("@$p", $Parameters[$p])
  18.         }
  19.    
  20.         # create the adapter
  21.         $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter($cmd)
  22.    
  23.         # fill and return the table.
  24.         $dt = New-Object System.Data.DataTable
  25.         $x = $SqlAdapter.Fill($dt)
  26.                 Write-Host "Rows affected $x" -fore green
  27.         $dt  # returns thhe table
  28.     }
  29.     Catch{
  30.         Throw $_
  31.     }
  32.            
  33. } ##Exec-Sproc
This topic is 7 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked