Page 1 of 1

Convert.ToBoolean in OD 19.4

Posted: Tue Dec 31, 2019 8:15 pm
by wjstarck
This code has been working for many years, but is suddenly broken in OD 19.4

Code: Select all

string command = "SELECT AddEnhancedMenuItems FROM anesthpreference";
return Convert.ToBoolean(DataCore.GetScalar(command));
So to get it working, I have to rewrite it as

Code: Select all

string command = "SELECT AddEnhancedMenuItems FROM anesthpreference";
string result = DataCore.GetScalar(command);
bool prefResult = Convert.ToBoolean(Convert.ToInt32(result));
return prefResult;
Why?

Re: Convert.ToBoolean in OD 19.4

Posted: Wed Jan 01, 2020 8:01 am
by cmcgehee
Did you used to store AddEnhancedMenuItems as "true" and now you're storing it at "1"?

Re: Convert.ToBoolean in OD 19.4

Posted: Wed Jan 01, 2020 10:13 am
by wjstarck
Always stored as 1 or 0

Re: Convert.ToBoolean in OD 19.4

Posted: Thu Jan 02, 2020 7:51 am
by cmcgehee
When I run Convert.ToBoolean("1") in C# 7.3 using .NET Framework 4.5.2 in Visual Studio 2019, it gives a FormatException. I cannot vouch for its behavior in older versions of C# or .NET.

Re: Convert.ToBoolean in OD 19.4

Posted: Fri Jan 03, 2020 10:05 am
by wjstarck
Chris-

I store those as tinyints in my tables instead of bools. Could that be the problem?

Re: Convert.ToBoolean in OD 19.4

Posted: Mon Jan 06, 2020 7:40 am
by cmcgehee
I don't think so. We store bools as tinyints as well.