I have the following PowerShell code:
Add-Type -AssemblyName System.Data
function SQLBuild
{
[DataTable] $dt = (New-Object -TypeName System.Data.DataTable)
$dt = fillDataTable
$dt.rows.count
foreach ($dr in $dt.rows)
{
Write-Host "$($dr[0])"
}
}
I am getting the following errors:
Cannot index into a null array.
Untitled2.ps1:19 char:43
+ Write-Host "$($dr[0])"
+ ~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At Untitled2.ps1:19 char:43
+ Write-Host "$($dr[0])"
+ ~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Can you please help me to understand why.