Today I found out that there is a difference between $null and [DBNull] in powershell. One of my projects uses a MySQL DB, a newer query returns null data depending on a few scenarios. Because of this my process would fail as the null value wasn’t being handled correctly. After some digging it turns out that when querying a DB there is a difference between nulls.
Example:
1 2 3 4 |
$result.SalesOrder $result.SalesOrder -eq $null $result.SalesOrder -eq [DBNull]::Value |
Result:
idAccount : 0017000000r3333
AccountName : 1009333
DateCreated : 03/02/2015 12:14:09
HomeFolder : 0
SalesOrder :
idAccount1 :
ProdLocation :
SalesOrder1 :
DateGen :
CustURL :
Processed :
False
True
Source: http://www.zeninteractions.com/2013/10/17/checking-for-null-in-powershell/