The obvious answer is below :-)
if ($DS -ne $null)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
Can anyone please tell me how I can test a DataSet contains at least a .Tables[0] or a DataTable is not null?
For in the mocked up example, where 1=2 is always going to return null and therefore both the commands fail.
In production I would be returning null 99% of the time so I need to test for it and move on when null.
$DS = (Invoke-Sqlcmd -ServerInstance "server" -Username "user" -Password "password" -Database "database" -Query "select 1,2,3 where 1=2" -As DataSet)
$DS.GetType()
$DT = (Invoke-Sqlcmd -ServerInstance "server" -Username "user" -Password "password" -Database "database" -Query "select 1,2,3 where 1=2" -As DataSet).Tables[0]
$DT.GetType()
The obvious answer is below :-)
if ($DS -ne $null)