Casting a boolean to an integer returns -1 for true?

前端 未结 9 816
醉梦人生
醉梦人生 2020-12-01 05:30

I am working with some VB.NET code that seems to be casting a boolean value to an integer using CInt(myBoolean). The odd thing that is happening is that it retu

9条回答
  •  时光说笑
    2020-12-01 05:47

    I have been having the same problem with MySQL as this has no Boolean type only a tinyint(1).

    My solution was to write a converter function to ensure that the values are correct before inserting them into the database

            Public Function BoolToMySql(bVal As Boolean) As Integer
                Dim retVal As Integer
                If bVal = True Then
                    retVal = 1
                Else
                    retVal = 0
                End If
                     BoolToMySql = retVal
            End Function
    

提交回复
热议问题