Functions/connect-WITsqltable.ps1
<#
.Synopsis Öppnar ett recordset med data .DESCRIPTION $dbconn Koppling till db $Table Vilken tabell behövs ej vid query $Query Använd denna fråga istället för en byggd $where Where sats ger "Select * FROM [dbo].[$table] where $where" $all Switch Ger "Select * FROM [dbo].[$table]" Utan query och Where och all ger "Select top(0) * FROM [dbo].[$table]" .EXAMPLE Example of how to use this cmdlet .EXAMPLE Another example of how to use this cmdlet #> function connect-WITsqltable { [CmdletBinding()] [Alias()] Param ( # Param1 help description [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] $dbconn, $Table, $Query, $where, [Switch]$all ) Begin { } Process { $rset = new-object -comobject ADODB.Recordset; $rset.CursorLocation=3 if ($all) { $query1="Select * FROM [dbo].[$table]" } elseif ($Query.Length -gt 1) { $query1=$query } elseif ($Where.Length -gt 1) { $query1="Select * FROM [dbo].[$table] where $where" } else { $query1="Select top(0) * FROM [dbo].[$table]" } $open=$rset.open($query1, $dbConn,2,4); } End { return $rset } } |