Posted by denty on Thu 26th Jan 14:24 (modification of post by denty view diff)
diff | download | new post
- Function Get-SqlData {
- <#
- .Synopsis
- Executes an SQL query using the defined connection string.
- .Description
- None yet.
- .Parameter
- #>
- Param(
- )
- $SqlConnection = New-Object Data.SqlClient.SqlConnection($ConnectionString)
- $SqlConnection.Open()
- $SqlDataAdapter = New-Object Data.SqlClient.SqlDataAdapter($SqlQuery, $SqlConnection)
- $DataTable = New-Object Data.DataTable
- [Void]$SqlDataAdapter.Fill($DataTable)
- $SqlConnection.Close()
- # Extract fields from the DataTable, then forcefully convert the table to PsCustomObject
- # this changes fields set to DBNull to Null and vastly simplifies checking later
- $DataTable | Select-Object * -Exclude Row*, Table, ItemArray, HasErrors | ConvertTo-Csv | ConvertFrom-Csv
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.