花费更多时间在PowerShell中提取SQL数据.遇到[System.DBNull] :: Value以及PowerShell在比较期间如何处理这些问题.
以下是我看到的行为示例以及变通方法
#DBNull values don't evaluate like Null...
if([System.DBNull]::Value){"I would not expect this to display"}
# The text displays.
if([string][System.DBNull]::Value){"This won't display, but is not intuitive"}
# The text does not display.
#DBNull does not let you use certain comparison operators
10 -gt [System.DBNull]::Value
# Could not compare "10" to "". Error: "Cannot convert value "" to type "System.Int32". Error: "Object cannot be cast from DBNull to other types.""
[System.DBNull]::Value -gt 10
# Cannot compare "" because it …Run Code Online (Sandbox Code Playgroud)