Test a null value in SQL Row

Hello,

I'd like to test in a sql query if a row is null (value validated in my sql browser)

I've tested

if (! $row[0]) -> always false
if ($row[0] -eq $null) -> always false

Thx for help.
SybuxAsked:
Who is Participating?
 
SybuxAuthor Commented:
Finally after googled again and more, I've found the solution in this article :

http://blogs.technet.com/b/industry_insiders/archive/2008/09/15/testing-for-database-null-values-from-powershell.aspx

Basicaly, you need to test with the [System.DBNull] object like this :

if ([System.DBNull]::Value.Equals($rows[0])) { value is null } else { value is filled }
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
try this:

if(    $row[0].count -eq 0      )


or

$row -eq $null

or

$result.hasrows -eq $false
0
 
Dan CraciunIT ConsultantCommented:
If !$row[0] is always false, this means $row[0] is never null.

Test to see what is stored in $row[0].
0
 
Dan CraciunIT ConsultantCommented:
You're right.

For completion sake:
- null means the absence of a reference to an object
- DBNull means a nonexistent database column
0
 
SybuxAuthor Commented:
Google is finally still best friend but after hours of search :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.