I have a value which I am trying to add as a parameter to a stored procedure.
The value of this parameter could either be a STRING of "1" or "NULL"
If it's NULL then I want to add the parameter of DBNull.Value
If it's "1" I want to add the parameter of 1 (int)
I have tried numerous combinations of syntax but cannot get it right.
This is what I have:
cmd.Parameters.Add(new SqlParameter("@LinkClickedId", (insertValuesSplit[12] == "NULL") ? Convert.ToInt16(insertValuesSplit[12]) : DBNull.Value));
But I have a syntax error of
Type of conditional expression cannot be determined because there is no implicit conversion between 'short' and 'System.DBNull' Can anyone suggest what the syntax should be please?