I have a line that is giving an error:
Type of conditional expression cannot be determined because there is no implicit conversion between ‘string’ and ‘int’
param[0].Value = form_request_id == null ? DBNull.Value.ToString() : form_request_id;
however, form_request_id is an int
How do I check for nulls in an int data type?
Your immediate problem isn’t that you’re checking for nulls in
form_request_id(which will actually always evaluate to false since you really need to use anint?for the value to actually be null).The real problem is that both sides of your conditional expression return different types (one is string and the other is int).
Since the
param[0].Valueshould really be different types based on the condition…you’re not going to be able to use the shortcut statement here. You’ll have to spell it out the long way:As I mentioned before, you still need to use
int?rather thanintso that your variable can appropriately hold a null value. When you do that, you shouldn’t even need the statement anymore because the database provider will see a null value and substituteDBNull.Valuefor you behind the scenes. The code would simply be: