Bob Goblin
Bob Goblin

Reputation: 1269

IF statement To Check If DataSet Is Empty

I am filling my data set with this $SqlAdapter.Fill($DataSet) then assigning the returned results to my variable like so $rowCount = $SqlAdapter.Fill($DataSet) Then using an if statement to determine if the rowcount is > 0 if($rowCount > 0) BUT my code never executes the if statement. It returns on screen 3 rows returned from my .Fill but that's it. Full code below:

$SqlAdapter.Fill($DataSet)
$rowCount = $SqlAdapter.Fill($DataSet)
if($rowCount > 0)
{
  [System.IO.Directory]::CreateDirectory("C:\Data\")
}

Upvotes: 2

Views: 7103

Answers (1)

Josh Stevens
Josh Stevens

Reputation: 4221

"Greater than" in PowerShell syntax is -gt. Try this:

$SqlAdapter.Fill($DataSet)
$rowCount = $SqlAdapter.Fill($DataSet)
if($rowCount -gt 0)
{
  [System.IO.Directory]::CreateDirectory("C:\Data\")
}

This link is quite helpful in terms of if and syntax for PowerShell.

Upvotes: 4

Related Questions