I have a table. And in the table, I have a field that stores the status of
something. I declare this status field as a "bit" data type in the sql
server. When I retrieve the value in my asp.net (in visual basic) code, is
this data a string, integer, char or object? Visual Basic doesn't seem to
have a bit data type.
Do you understand what I mean? Do you recommend me using the "bit" data
type? Or should I use varchar(1) instead?
Thank you.Hi
The BIT allows 0, 1 and NULL.
A VB/VB.NET Boolean datatype has 0 for false and -1 for true (c# has 0 for
false and 1 for true)
There is not direct match, but you could have some code in your Middle Tier
that converts +1 to -1 and the opposite when you write back to SQL Server.
Generally, it is best to always evaluate against false, as 0 is false in all
languages.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:E23EF238-9630-4111-A47E-A9627CD4B954@.microsoft.com...
>I have a table. And in the table, I have a field that stores the status of
> something. I declare this status field as a "bit" data type in the sql
> server. When I retrieve the value in my asp.net (in visual basic) code, is
> this data a string, integer, char or object? Visual Basic doesn't seem to
> have a bit data type.
> Do you understand what I mean? Do you recommend me using the "bit" data
> type? Or should I use varchar(1) instead?
> Thank you.|||I personally prefer CHAR(1) for status columns. Bit columns can take up less
space, but only if you have more than one bit column in a table. CHAR(1) has
the advantage that there is no confusion over the meaning of the values (Y/N
is clearer than 1/0), and you don't have to change your database design if
it turns out that there are more than 2 different statuses you want to keep
track of.
CHAR(1) is better than VARCHAR(1), because a variable length column has an
overhead of 2 bytes to store the length of the column, which a fixed length
column doesn't have.
Jacco Schalkwijk
SQL Server MVP
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:E23EF238-9630-4111-A47E-A9627CD4B954@.microsoft.com...
>I have a table. And in the table, I have a field that stores the status of
> something. I declare this status field as a "bit" data type in the sql
> server. When I retrieve the value in my asp.net (in visual basic) code, is
> this data a string, integer, char or object? Visual Basic doesn't seem to
> have a bit data type.
> Do you understand what I mean? Do you recommend me using the "bit" data
> type? Or should I use varchar(1) instead?
> Thank you.|||Hi
I'd recommend you using CHAR(1) rather BIT datatype, because many
programming languages are interpreted on the client side differently. If I
remember well in VB. NET True-1 and False =0
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:E23EF238-9630-4111-A47E-A9627CD4B954@.microsoft.com...
> I have a table. And in the table, I have a field that stores the status of
> something. I declare this status field as a "bit" data type in the sql
> server. When I retrieve the value in my asp.net (in visual basic) code, is
> this data a string, integer, char or object? Visual Basic doesn't seem to
> have a bit data type.
> Do you understand what I mean? Do you recommend me using the "bit" data
> type? Or should I use varchar(1) instead?
> Thank you.|||Thank you guys. I think I'll use CHAR(1) instead then. And so, I guess I can
use a Char datatype in asp.net to represent this value.
"Uri Dimant" wrote:
> Hi
> I'd recommend you using CHAR(1) rather BIT datatype, because many
> programming languages are interpreted on the client side differently. If I
> remember well in VB. NET True-1 and False =0
> "wrytat" <wrytat@.discussions.microsoft.com> wrote in message
> news:E23EF238-9630-4111-A47E-A9627CD4B954@.microsoft.com...
>
>|||> CHAR(1) is better than VARCHAR(1), because a variable length column has an
> overhead of 2 bytes to store the length of the column, which a fixed lengt
h
> column doesn't have.
Is this the only difference between CHAR and VARCHAR? Say if I have 2
fields, 1 declared as CHAR(20), while the other as VARCHAR(20), both to stor
e
email address. Can I use String to represent both at my ASP.NET programming?
And which will be better?|||See Gert-Jan Strik's comments about this here:
http://groups.google.co.uk/groups?q...n+agree+factors
Steve Kass
Drew University
wrytat wrote:
>Is this the only difference between CHAR and VARCHAR? Say if I have 2
>fields, 1 declared as CHAR(20), while the other as VARCHAR(20), both to sto
re
>email address. Can I use String to represent both at my ASP.NET programming
?
>And which will be better?
>
>|||No, values stored in a Char(20) are not the same as values stored in a
VarChar(20). In the former case, if the value stored is less than 20 charact
ers,
it is padded with spaces. In the later case, it only stores the data passed
so
an 18 character string only takes up 18 bytes of space.
Given that, values stored in a Char(1) are almost the same as values stored
in a
VarChar(1). However, if you know that a value can only be one character, you
get
a small performance improvement by using a Char(1) in that the system does n
ot
have to maintain the length of data and the system can preallocate a specifi
ed
amount of space.
In general, I find Char data types to be a royal pain. Unless I know for a f
act
that a value must absolutely be equal to the given length (e.g Y/N values),
I
always prefer VarChar over Char because it makes it much more intuitive for
other developers to query against.
Thomas
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:C4DAD7EC-8FEB-4F84-94F7-4774C2B441D0@.microsoft.com...
> Is this the only difference between CHAR and VARCHAR? Say if I have 2
> fields, 1 declared as CHAR(20), while the other as VARCHAR(20), both to st
ore
> email address. Can I use String to represent both at my ASP.NET programmin
g?
> And which will be better?
>
No comments:
Post a Comment