I have a stored procedure returning a boolean varialbe :
Here is my C# code that works when I try to return an int variable.But it doesnt work when I try it for bool.
DbCommand dbCommand = db.GetStoredProcCommand("spGetConfigureAlerts");
object o = db.ExecuteScalar(dbCommand);
bool item = o == null ? 0 : (bool)o;
return item;
I have it as shown above , but on line three it says that :
Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'bool'
How can I solve it ?
Why do you use 0 at all if you want to initialize a bool variable?
bool item = (o == null || DBNull.Value == o) ? false : (bool)o;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With