I have a method which is connecting to a database via Odbc. The stored procedure which I\'m calling has a return value which from the database side is a \'Char\'. Right now I\'
(returnValue != "1" ? false : true);
My solution (vb.net):
Private Function ConvertToBoolean(p1 As Object) As Boolean
If p1 Is Nothing Then Return False
If IsDBNull(p1) Then Return False
If p1.ToString = "1" Then Return True
If p1.ToString.ToLower = "true" Then Return True
Return False
End Function
How about:
return (returnValue == "1");
or as suggested below:
return (returnValue != "0");
The correct one will depend on what you are looking for as a success result.
Or if the Boolean value is not been returned, you can do something like this:
bool boolValue = (returnValue == "1");
In a single line of code:
bool bVal = Convert.ToBoolean(Convert.ToInt16(returnValue))
If you don't want to convert.Just use;
bool _status = status == "1" ? true : false;
Perhaps you will return the values as you want.