- function Exec-Sproc{
- param(
- [System.Data.SqlClient.SqlConnection]$Conn,
- $Sproc,
- [hashtable]$Parameters
- )
- Try{
- $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
- $SqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure
- $SqlCmd.CommandTimeout = $script:SqlCommandTimeOut;
- if ($Conn.State -ne 'Open') { $Conn.open(); }
- $ build the comamnd
- $cmd = $Conn.CreateCommand()
- $cmd.CommandText = $Sproc
- foreach ($p in $Parameters.Keys) {
- [Void]$cmd.Parameters.AddWithValue("@$p", $Parameters[$p])
- }
- # create the adapter
- $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter($cmd)
- # fill and return the table.
- $dt = New-Object System.Data.DataTable
- $x = $SqlAdapter.Fill($dt)
- Write-Host "Rows affected $x" -fore green
- $dt # returns thhe table
- }
- Catch{
- Throw $_
- }
- } ##Exec-Sproc
pipeline stopped error when closing out-gridview
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.
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.
Re: pipeline stopped error when closing out-gridview
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.