Different between database bit and vb true and false

patrick24601

Active member
Joined
May 16, 2005
Messages
34
A SQL Server database stores a bit value as 1 or 0.
Visual Basic stores true false as -1 and 0.

As far as I can tell every time you read a bit column you are going to have to multiple it by -1 in order to test for true/false in VB?

Did I get this right or is there an easier way (without storing the value as an integer in sql server) ?

Thanks,
Patrick
 
Ive got a feeling that Vb treats anything other than a 0 as true (though i might be thinking of something else) which means there would be no problem.
Logic wise if you want to test for true use something along lines of Not(Value =false)
As false is the same in both cases and and will return true for either 1 or -1.
 
(assuming the value is stored as a Signed Byte)


False = 0
True = "NOT" False:

False = 0000 (in binary)
True = NOT 0000 (in binary) = 1111

Using Twos complement, 1111 = (-1)

so, True = -1

HOWEVER...

VB.net will recognise anything that is "not" false as being true!

B.
 
Back
Top