By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Vb.net Oracle Boolean database numeric value 1

P: 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)

Expand|Select|Wrap|Line Numbers
  1. oRow("CAT_SELECTED") = True
  2. If oRow("CAT_SELECTED") = True Then
  3.     ' Not True
  4. End If

I found this information about <OracleBoolean 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...
Nov 27 '13 #1

✓ answered by Frinavale

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 OracleDataReader class and discovered that it has a GetBoolean method that you should probably consider using.

-Frinny

Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
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 OracleDataReader class and discovered that it has a GetBoolean method that you should probably consider using.

-Frinny
Dec 2 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.