How to convert “0” and “1” to false and true

前端 未结 9 688
無奈伤痛
無奈伤痛 2021-02-06 19:59

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\'

9条回答
  •  猫巷女王i
    2021-02-06 20:33

    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
    

提交回复
热议问题