Created
August 17, 2022 18:26
-
-
Save Warrenn/d6b344d31e7ec63a08423a84f00fb345 to your computer and use it in GitHub Desktop.
get a dataset from a database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DataSet($sqlCommand, $parameters, $connectionString) { | |
$connection = new-object system.data.SqlClient.SQLConnection($connectionString) | |
$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection) | |
$dataset = New-Object System.Data.DataSet | |
$parameters | Select-Object -ExpandProperty Keys | %{ | |
$command.Parameters.Add($_, $parameters[$_]) | |
} | |
try{ | |
$connection.Open() | |
$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command | |
$adapter.Fill($dataSet) | Out-Null | |
} | |
finally { | |
$connection.Close() | |
} | |
return $dataSet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment