pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

[GeoBot] The Ego Bot View Help

Posted by denty on Thu 26th Jan 14:24 (modification of post by denty view diff)
diff | download | new post

  1. Function Get-SqlData {
  2.   <#
  3.     .Synopsis
  4.       Executes an SQL query using the defined connection string.
  5.     .Description
  6.       None yet.
  7.     .Parameter
  8.   #>
  9.  
  10.   Param(
  11.     [String]$ConnectionString,
  12.     [String]$Query
  13.   )
  14.  
  15.   $SqlConnection = New-Object Data.SqlClient.SqlConnection($ConnectionString)
  16.   $SqlConnection.Open()
  17.  
  18.   $SqlDataAdapter = New-Object Data.SqlClient.SqlDataAdapter($SqlQuery, $SqlConnection)
  19.  
  20.   $DataTable = New-Object Data.DataTable
  21.   [Void]$SqlDataAdapter.Fill($DataTable)
  22.  
  23.   $SqlConnection.Close()
  24.  
  25.   # Extract fields from the DataTable, then forcefully convert the table to PsCustomObject
  26.   # this changes fields set to DBNull to Null and vastly simplifies checking later
  27.   $DataTable | Select-Object * -Exclude Row*, Table, ItemArray, HasErrors | ConvertTo-Csv | ConvertFrom-Csv
  28. }

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.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings