M
Mark
Below is code that populates a single SQL Server parameter value. The
parameter is a varchar, but could be a null value. Why doesn't the ? :
syntax in the second piece of code work?? Isn't it identical to the first
option? The error claims that there is no way to convert DBNull.Value to a
string. Does a ? : have to have a consistent format in the THEN and ELSE?
Thanks!
-Mark
*** WORKS ***
if (strCategory.Equals(string.Empty))
{
sqlComm.Parameters["@task_category"].Value = DBNull.Value;
}
else
{
sqlComm.Parameters["@task_category"].Value = strCategory;
}
*** DOESN'T WORK ***
sqlComm.Parameters["@task_category"].Value =
(strCategory.Equals(string.Empty)) ? DBNull.Value : strCategory;
parameter is a varchar, but could be a null value. Why doesn't the ? :
syntax in the second piece of code work?? Isn't it identical to the first
option? The error claims that there is no way to convert DBNull.Value to a
string. Does a ? : have to have a consistent format in the THEN and ELSE?
Thanks!
-Mark
*** WORKS ***
if (strCategory.Equals(string.Empty))
{
sqlComm.Parameters["@task_category"].Value = DBNull.Value;
}
else
{
sqlComm.Parameters["@task_category"].Value = strCategory;
}
*** DOESN'T WORK ***
sqlComm.Parameters["@task_category"].Value =
(strCategory.Equals(string.Empty)) ? DBNull.Value : strCategory;