I got this parameter:
$objDbCmd.Parameters.Add("@telephone", [System.Data.SqlDbType]::VarChar, 18) | Out-Null; $objDbCmd.Parameters["@telephone"].Value = $objUser.Telephone;
If the string $objUser.Telephone may be empty. If it is empty, how can I convert it to [DBNull]::Value ?
I tried:
if ([string]:IsNullOrEmpty($objUser.Telephone)) { $objUser.Telephone = [DBNull]::Value };
But this gives me an error:
Calling an ExecuteNonQuery exception with arguments "0": "Failed to convert the parameter value from ResultPropertyValueCollection to string."
And if I convert it to a string, it inserts the empty string "" , not DBNull .
How can I do that?
Thanks.
sql powershell dbnull
Tommy jakobsen
source share