Hi,
The three above seem to form an evil combination. ;-)
For now, I use varchar(5) in my SqlServer 2000 db and fill it with "True" or "False", which VB understands as boolean values in my .aspx/.aspx.vb pages.
Is there no way of using Bit instead in SqlServer, or even 0/1, and easily bind it in VB? How do others do it? (I've only seen other people struggling with this, and not any solution).
I can't understand why a language such as VB cannot be allowed to understand both True/False, 1/0, and Y/N!
Muchos gracias in advance,
Pettrer
I do not know what about Y/N but 0/1 in VB is a little opposite because is 0/-1 so -1 is true in VB and 1 is true in SQL Bit field.
Thanks
|||Thanks, but the problem is that VB only writes "True" and "False" to the database. Of course i might be able to change it in the INSERT/UPDATE statements, but then I read somewhere that booleans are not indexed in SqlServer, so I guess that it's bo point using it anyway. Am i wrong in this assumption? Please help.
Pettrer, very puzzled ;-)
|||If your field is bit field is stored on SQL as 0 or 1 but in gridView in VB is be displayed as True/False by default (or as check box if you ask for this )check this code :
select
cast(-10asbit) true,cast(0asbit) false,cast(1asbit) true,cast(10asbit) trueAs you could see from this example I was a little wrong in SQL looks like false is 0 and everything else is true
Thanks
|||Yes, you're right - everything that is not 0 is true; absint - not absinth! ;-) - comes to mind...
However, my questions are (forgive me if I misunderstood your reply):
1. How do I get from the checkbox to boolean in the db (the other way becomes correct automatically )?
2. Is this a behaviour I want (ie having booleans in the db), as I read somewhere that booleans are not indexed - which sounds really strange to me, as that would affect server performance)? I could of course convert everything to 0/1 as integers, but it seems rather stupid to do that. What do people do? Is no one using VB with SqlServer?
Pettrer, puzzled! :-)
|||Use bit data type which is Ture/False in the database and you can set this column to required and with a default if you want.|||Limno,
Thanks for replying. You're right of course, but the problem is not the SqlServer db per se, but how badly VB works together with it. I took a look in the db and realised that if I do this the boolean way, it's still one byte per entry, as they can't be divided into the bits. If I use the strings True and False, I get two bytes instead. It's really not a big deal, then (my advice to other VB developers must be to use the textual representation in the db). But it's really, really strange!
Pettrer
No comments:
Post a Comment