Database Reference
In-Depth Information
of the ield, and IsDBNull to check for null values:
while ($reader.Read())
{
$city = $reader.GetString($reader.GetOrdinal("city"))
$stateProvince = $null
if (!$reader.IsDBNull($reader.GetOrdinal("state_province")))
{
$stateProvince = $reader.GetString($reader.
GetOrdinal("state_province"))
}
"City is '{0}', State/Province is '{1}'" -f $city,
$stateProvince
}
3.
After iterating over the data, we close the DataReader before closing the connection:
$reader.Close()
Reading in this manner is more tedious than illing a DataTable but the memory
savings may be worth it in cases where you are working with large amounts of data.
Filtering and exporting data (Simple)
In this recipe we will look at iltering and sorting data and outputting data to different
ile formats.
Getting ready
Complete all previous recipes including Retrieving data (Simple) .
How to do it...
1. Since we want to output iles to the script's directory, deine this function:
function Get-ScriptDirectory
{
if (Test-Path variable:\hostinvocation)
{
$FullPath=$hostinvocation.MyCommand.Path
}
else
{
 
Search WWH ::




Custom Search