Vb.net Oracle Boolean database numeric value 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ornekhakan
    New Member
    • Nov 2013
    • 1

    #1

    Vb.net Oracle Boolean database numeric value 1

    Hi,
    Vb.net boolean True is representing -1 , this code work for Ms Access, Ms SQL ect. But not work Oracle, because Oracle true is setting 1 in database (not -1)

    Code:
    oRow("CAT_SELECTED") = True
    If oRow("CAT_SELECTED") = True Then
        ' Not True
    End If

    I found this information about <OracleBoolea n Structure> http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
    But I need a sample change for true 1 to -1 for oracle. Thanks for all helps...
    Last edited by Frinavale; Dec 2 '13, 03:16 PM.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    In .NET, a Boolean on a 32 bit operating system takes up 4 bytes. On a 64 bit operating system it takes up 8 bytes.

    A True Boolean value means that every bit in the 4 or 8 Bytes allocated to the Boolean is set to 1.

    The first bit position in a signed integer represents if the integer is positive or negative.

    So, if every bit is set to 1 this means that the value is negative.

    Which explains why a Boolean True becomes -1 when you cast it into an Integer in VB.NET

    When you are planning on storing a Boolean into a MS SQL Server Database, you indicate that the column should be a "Bit" type. In MS SQL Server, 1 represents true and 0 represents false.

    Obviously this is a different data type than the 4/8 Byte .NET Boolean that your VB.NET application uses. This is why .NET has built in tools that automatically convert database data types to .NET data types when storing and retrieving the data.

    I have not personally connected to an Oracle database with .NET code before so I took a look at the documentation for the OracleDataReade r class and discovered that it has a GetBoolean method that you should probably consider using.

    -Frinny
    Last edited by Frinavale; Dec 2 '13, 04:09 PM.

    Comment

    Working...