Don"t Understand Error Message (Database)

Don"t Understand Error Message (Database)

am 11.01.2008 20:43:42 von Jonathan Wood

The following code raises the error "Specified cast is not valid."

MembershipUser user = Membership.GetUser(userId);
DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
UserId='" + userId.ToString() + "'");
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
return null;
ClientEx client = new ClientEx();
client.ClientData = new Client();
client.ClientData.Email = user.UserName;
client.ClientData.UserID = user.ProviderUserKey;
client.ClientData.LastLogin = user.LastLoginDate;
DataRow dr = ds.Tables[0].Rows[0];

// ...

if (!Convert.IsDBNull(dr["Sex"]))
client.Sex = (int)dr["Sex"]; <<== ERROR HERE!

// ...

In the database table, Sex has a data type=smallint and nullable=True, and
client.Sex has a data type of int.

If I attempt to examine the contents of dr["Sex"] in the debugger, it shows
a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"] in
the debugger, it shows an error about not being able to unbox (sorry I no
longer have the exact text).

Any suggestions?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 11.01.2008 20:51:58 von mark

"Jonathan Wood" wrote in message
news:%23%23eIKpIVIHA.4196@TK2MSFTNGP04.phx.gbl...

> The following code raises the error "Specified cast is not valid."

Yes, it would do...

> if (!Convert.IsDBNull(dr["Sex"]))

if (dr["Sex"] != DBNull.Value)

> In the database table, Sex has a data type=smallint

So the Sex field can have a range of values from -32,768 to 32,767...?
http://msdn2.microsoft.com/en-us/library/aa933198(SQL.80).as px


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

RE: Don"t Understand Error Message (Database)

am 11.01.2008 21:31:00 von pbromberg

What type is client.Sex? Looks like whatever it is, it cannot accept int as a
value. Unless the Convert of the (int)dr["Sex"] is failing because it
itself is not an integer.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


"Jonathan Wood" wrote:

> The following code raises the error "Specified cast is not valid."
>
> MembershipUser user = Membership.GetUser(userId);
> DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
> UserId='" + userId.ToString() + "'");
> if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
> return null;
> ClientEx client = new ClientEx();
> client.ClientData = new Client();
> client.ClientData.Email = user.UserName;
> client.ClientData.UserID = user.ProviderUserKey;
> client.ClientData.LastLogin = user.LastLoginDate;
> DataRow dr = ds.Tables[0].Rows[0];
>
> // ...
>
> if (!Convert.IsDBNull(dr["Sex"]))
> client.Sex = (int)dr["Sex"]; <<== ERROR HERE!
>
> // ...
>
> In the database table, Sex has a data type=smallint and nullable=True, and
> client.Sex has a data type of int.
>
> If I attempt to examine the contents of dr["Sex"] in the debugger, it shows
> a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"] in
> the debugger, it shows an error about not being able to unbox (sorry I no
> longer have the exact text).
>
> Any suggestions?
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
>

Re: Don"t Understand Error Message (Database)

am 11.01.2008 23:21:20 von Jonathan Wood

As stated, client.Sex is an int.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Peter Bromberg [C# MVP]" wrote in message
news:23BAA369-2F6C-490D-9C6D-A91A08E2E2E8@microsoft.com...
> What type is client.Sex? Looks like whatever it is, it cannot accept int
> as a
> value. Unless the Convert of the (int)dr["Sex"] is failing because it
> itself is not an integer.
>
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "Jonathan Wood" wrote:
>
>> The following code raises the error "Specified cast is not valid."
>>
>> MembershipUser user = Membership.GetUser(userId);
>> DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
>> UserId='" + userId.ToString() + "'");
>> if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count ==
>> 0)
>> return null;
>> ClientEx client = new ClientEx();
>> client.ClientData = new Client();
>> client.ClientData.Email = user.UserName;
>> client.ClientData.UserID = user.ProviderUserKey;
>> client.ClientData.LastLogin = user.LastLoginDate;
>> DataRow dr = ds.Tables[0].Rows[0];
>>
>> // ...
>>
>> if (!Convert.IsDBNull(dr["Sex"]))
>> client.Sex = (int)dr["Sex"]; <<== ERROR HERE!
>>
>> // ...
>>
>> In the database table, Sex has a data type=smallint and nullable=True,
>> and
>> client.Sex has a data type of int.
>>
>> If I attempt to examine the contents of dr["Sex"] in the debugger, it
>> shows
>> a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"]
>> in
>> the debugger, it shows an error about not being able to unbox (sorry I no
>> longer have the exact text).
>>
>> Any suggestions?
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>>

Re: Don"t Understand Error Message (Database)

am 11.01.2008 23:30:00 von Jonathan Wood

Mark,

>> The following code raises the error "Specified cast is not valid."
>
> Yes, it would do...
>
>> if (!Convert.IsDBNull(dr["Sex"]))
>
> if (dr["Sex"] != DBNull.Value)

So what does that mean? Does that mean dr["Sex"] was, in fact, null but my
check was wrong? And what the heck does Convert.IsDBNull() do? This seemed
to work on some other fields.

Actually, I just tried this:

if (dr["Sex"] != DBNull.Value)
client.Sex = (int)dr["Sex"];

And I seem to get exactly the same error on the same line.

>> In the database table, Sex has a data type=smallint
>
> So the Sex field can have a range of values from -32,768 to 32,767...?

Hey, we like our site to support all types. ;-) Seriously, it's coming from
a RadioButtonList and just seemed to make more sense to use an int. Besides,
I don't see how a database can store a bit field using less than a byte
anyway.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 11.01.2008 23:32:32 von Jonathan Wood

Actually, it looks like dr["Sex"] was NULL. But I thought I was testing for
that.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Peter Bromberg [C# MVP]" wrote in message
news:23BAA369-2F6C-490D-9C6D-A91A08E2E2E8@microsoft.com...
> What type is client.Sex? Looks like whatever it is, it cannot accept int
> as a
> value. Unless the Convert of the (int)dr["Sex"] is failing because it
> itself is not an integer.
>
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "Jonathan Wood" wrote:
>
>> The following code raises the error "Specified cast is not valid."
>>
>> MembershipUser user = Membership.GetUser(userId);
>> DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
>> UserId='" + userId.ToString() + "'");
>> if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count ==
>> 0)
>> return null;
>> ClientEx client = new ClientEx();
>> client.ClientData = new Client();
>> client.ClientData.Email = user.UserName;
>> client.ClientData.UserID = user.ProviderUserKey;
>> client.ClientData.LastLogin = user.LastLoginDate;
>> DataRow dr = ds.Tables[0].Rows[0];
>>
>> // ...
>>
>> if (!Convert.IsDBNull(dr["Sex"]))
>> client.Sex = (int)dr["Sex"]; <<== ERROR HERE!
>>
>> // ...
>>
>> In the database table, Sex has a data type=smallint and nullable=True,
>> and
>> client.Sex has a data type of int.
>>
>> If I attempt to examine the contents of dr["Sex"] in the debugger, it
>> shows
>> a value of 0x0000. If I attempt to examine the contents of (int)dr["Sex"]
>> in
>> the debugger, it shows an error about not being able to unbox (sorry I no
>> longer have the exact text).
>>
>> Any suggestions?
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>>

Re: Don"t Understand Error Message (Database)

am 11.01.2008 23:45:49 von mark

"Jonathan Wood" wrote in message
news:u4%23%23FGKVIHA.1204@TK2MSFTNGP03.phx.gbl...

>>> The following code raises the error "Specified cast is not valid."
>>
>> Yes, it would do...
>>
>>> if (!Convert.IsDBNull(dr["Sex"]))
>>
>> if (dr["Sex"] != DBNull.Value)
>
> So what does that mean? Does that mean dr["Sex"] was, in fact, null but my
> check was wrong?

I believe so...

> And what the heck does Convert.IsDBNull() do? This seemed to work on some
> other fields.

It (supposedly) does exactly the same thing:
http://msdn2.microsoft.com/en-us/library/system.convert.isdb null.aspx

but I've found it to be an extremely unreliable way of checking for a null
value in a database field...

> Actually, I just tried this:
>
> if (dr["Sex"] != DBNull.Value)
> client.Sex = (int)dr["Sex"];
>
> And I seem to get exactly the same error on the same line.

Hmm - OK... Set a breakpoint on the first line above and, in the Immediate
window, inspect dr["Sex"]

>>> In the database table, Sex has a data type=smallint
>>
>> So the Sex field can have a range of values from -32,768 to 32,767...?
>
> Hey, we like our site to support all types. ;-) Seriously, it's coming
> from a RadioButtonList and just seemed to make more sense to use an int.

I don't understand the thinking behind that at all...

> Besides, I don't see how a database can store a bit field using less than
> a byte anyway.

SQL Server (and several other RDBMS) can:

http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver .management.smo.datatype.bit.aspx

My slightly tongue-in-cheek point was that you're using a larger datatype
than is necessary... For gender, I tend to use char(1)...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 11.01.2008 23:48:02 von Jonathan Wood

I figured this out. It only works if I cast using (short) insteat of (int).
I have no idea why that is--converting from a 16-bit integer to a 32-bit
integer is a trivial task, in fact one that the compiler still does after my
change.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Jonathan Wood" wrote in message
news:%23%23eIKpIVIHA.4196@TK2MSFTNGP04.phx.gbl...
> The following code raises the error "Specified cast is not valid."
>
> MembershipUser user = Membership.GetUser(userId);
> DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE
> UserId='" + userId.ToString() + "'");
> if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
> return null;
> ClientEx client = new ClientEx();
> client.ClientData = new Client();
> client.ClientData.Email = user.UserName;
> client.ClientData.UserID = user.ProviderUserKey;
> client.ClientData.LastLogin = user.LastLoginDate;
> DataRow dr = ds.Tables[0].Rows[0];
>
> // ...
>
> if (!Convert.IsDBNull(dr["Sex"]))
> client.Sex = (int)dr["Sex"]; <<== ERROR HERE!
>
> // ...
>
> In the database table, Sex has a data type=smallint and nullable=True, and
> client.Sex has a data type of int.
>
> If I attempt to examine the contents of dr["Sex"] in the debugger, it
> shows a value of 0x0000. If I attempt to examine the contents of
> (int)dr["Sex"] in the debugger, it shows an error about not being able to
> unbox (sorry I no longer have the exact text).
>
> Any suggestions?
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>

Re: Don"t Understand Error Message (Database)

am 12.01.2008 00:05:03 von Jonathan Wood

Mark,

>> And I seem to get exactly the same error on the same line.
>
> Hmm - OK... Set a breakpoint on the first line above and, in the Immediate
> window, inspect dr["Sex"]

I described that in my original post. At any rate, the fix was to type cast
to a short instead of an int, which doesn't seem like it should be the case.

>> Besides, I don't see how a database can store a bit field using less than
>> a byte anyway.
>
> SQL Server (and several other RDBMS) can:
>
> http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver .management.smo.datatype.bit.aspx
> My slightly tongue-in-cheek point was that you're using a larger datatype
> than is necessary... For gender, I tend to use char(1)...

I didn't see where that link talked about the actual amount of storage used
to store bits in the database, I suppose it's possible to optimize bit
fields if they are stored contiguously, rather than with the other fields in
the same row, but I wouldn't have thought that's how it's done. At any rate,
I've used both char(1) and bit but I'm more comfortable using smallint in
this particular case.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 12.01.2008 01:15:28 von mark

"Jonathan Wood" wrote in message
news:OcQQrZKVIHA.4476@TK2MSFTNGP06.phx.gbl...

> I didn't see where that link talked about the actual amount of storage
> used to store bits in the database,

OK.

> I suppose it's possible to optimize bit fields if they are stored
> contiguously, rather than with the other fields in the same row, but I
> wouldn't have thought that's how it's done.

Not sure what you're talking about there...

> At any rate, I've used both char(1) and bit but I'm more comfortable using
> smallint in this particular case.

I simply can't fathom that at all...

Struggling to work out how the entity of 'gender' can ever be considered as
a numeric entity but, even if you consider that 'male' is somehow 1 and
'female' is somehow 2, then surely you'd use a tinyint rather than a
smallint, otherwise you're using twice as much storage space as you need...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 02:51:57 von Jonathan Wood

Mark,

> Struggling to work out how the entity of 'gender' can ever be considered
> as a numeric entity but, even if you consider that 'male' is somehow 1 and
> 'female' is somehow 2, then surely you'd use a tinyint rather than a
> smallint, otherwise you're using twice as much storage space as you
> need...

As I pointed out, the data is collected via a RadioButtonList. This control
returns an integer to indicate the selection, and I'm simply storing this
value as an integer.

Perhaps a byte would be better--isn't that a tinyint? But I see no reason to
deal with conversions to another data type here, particularly when I think a
single byte is the least amount of storage space that most fields could
occupy.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:07:26 von mark

"Jonathan Wood" wrote in message
news:uZu772LVIHA.2368@TK2MSFTNGP05.phx.gbl...

> Perhaps a byte would be better

Yes it would - or a char(1)...

> isn't that a tinyint?

Yes - a tinyint and a char(1) both occupy one byte...

> a single byte is the least amount of storage space that most fields could
> occupy.

Correct, apart from bit fields for boolean values, but that doesn't apply
here...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:24:01 von Jonathan Wood

Changed to a tinyint, along with several other fields based on CheckBoxList
controls (some with several different options).

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" wrote in message
news:u6XmChMVIHA.1208@TK2MSFTNGP05.phx.gbl...
> "Jonathan Wood" wrote in message
> news:uZu772LVIHA.2368@TK2MSFTNGP05.phx.gbl...
>
>> Perhaps a byte would be better
>
> Yes it would - or a char(1)...
>
>> isn't that a tinyint?
>
> Yes - a tinyint and a char(1) both occupy one byte...
>
>> a single byte is the least amount of storage space that most fields could
>> occupy.
>
> Correct, apart from bit fields for boolean values, but that doesn't apply
> here...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:30:59 von mark

"Jonathan Wood" wrote in message
news:eHwkYqMVIHA.1208@TK2MSFTNGP03.phx.gbl...

> "Mark Rae [MVP]" wrote in message
> news:u6XmChMVIHA.1208@TK2MSFTNGP05.phx.gbl...
>> "Jonathan Wood" wrote in message
>> news:uZu772LVIHA.2368@TK2MSFTNGP05.phx.gbl...
>>
>>> Perhaps a byte would be better
>>
>> Yes it would - or a char(1)...
>>
>>> isn't that a tinyint?
>>
>> Yes - a tinyint and a char(1) both occupy one byte...
>>
>>> a single byte is the least amount of storage space that most fields
>>> could occupy.
>>
>> Correct, apart from bit fields for boolean values, but that doesn't apply
>> here...
>
> Changed to a tinyint, along with several other fields based on
> CheckBoxList controls (some with several different options).

So, how do you tell the difference between the two genders when you're using
a tinyint...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:47:17 von Jonathan Wood

Mark,

>> Changed to a tinyint, along with several other fields based on
>> CheckBoxList controls (some with several different options).
>
> So, how do you tell the difference between the two genders when you're
> using a tinyint...?

Not sure I understand the question. As it is, Male is the first option so
Male == 0 and Female == 1. I tried creating enums for this (and the other
options) but stupid C# has problems with if (i == sexesMale). Oh well, I can
write code that simply tests the value for being 0 or 1.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:53:20 von mark

"Jonathan Wood" wrote in message
news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...

>> So, how do you tell the difference between the two genders when you're
>> using a tinyint...?
>
> Not sure I understand the question. As it is, Male is the first option so
> Male == 0 and Female == 1.

That seems totally unnatural and unintuitive to me...

When you use char(1), male is 'M' and female is 'F'...

A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really weird...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 04:59:01 von Jonathan Wood

Hmm... I'm not sure how long you've been programming but it doesn't seem at
all odd to me. At any rate, it's simply used for a couple of calculations
and on a report. There will be no queries based on it.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" wrote in message
news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
> "Jonathan Wood" wrote in message
> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>
>>> So, how do you tell the difference between the two genders when you're
>>> using a tinyint...?
>>
>> Not sure I understand the question. As it is, Male is the first option so
>> Male == 0 and Female == 1.
>
> That seems totally unnatural and unintuitive to me...
>
> When you use char(1), male is 'M' and female is 'F'...
>
> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
> weird...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 14:38:32 von me

"Jonathan Wood" wrote in message
news:eSpF89MVIHA.4364@TK2MSFTNGP02.phx.gbl...
> Hmm... I'm not sure how long you've been programming but it doesn't seem
> at all odd to me. At any rate, it's simply used for a couple of
> calculations and on a report. There will be no queries based on it.


if the values are 0 and 1 then you should use bit
0 = false
1 = true

entred as you would a int

INSERT INTO dataTypes (aBit)Values(1)


>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "Mark Rae [MVP]" wrote in message
> news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
>> "Jonathan Wood" wrote in message
>> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>>
>>>> So, how do you tell the difference between the two genders when you're
>>>> using a tinyint...?
>>>
>>> Not sure I understand the question. As it is, Male is the first option
>>> so Male == 0 and Female == 1.
>>
>> That seems totally unnatural and unintuitive to me...
>>
>> When you use char(1), male is 'M' and female is 'F'...
>>
>> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
>> weird...
>>
>>
>> --
>> Mark Rae
>> ASP.NET MVP
>> http://www.markrae.net
>

Re: Don"t Understand Error Message (Database)

am 12.01.2008 15:01:13 von mark

"Jonathan Wood" wrote in message
news:eSpF89MVIHA.4364@TK2MSFTNGP02.phx.gbl...

> "Mark Rae [MVP]" wrote in message
> news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
>> "Jonathan Wood" wrote in message
>> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>>
>>>> So, how do you tell the difference between the two genders when you're
>>>> using a tinyint...?
>>>
>>> Not sure I understand the question. As it is, Male is the first option
>>> so Male == 0 and Female == 1.
>>
>> That seems totally unnatural and unintuitive to me...
>>
>> When you use char(1), male is 'M' and female is 'F'...
>>
>> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
>> weird...
>
> I'm not sure how long you've been programming

LOL! About 30 years or so...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 15:02:35 von mark

"ThatsIT.net.au" wrote in message
news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...

> if the values are 0 and 1 then you should use bit

Unless the field is used in any query criteria, as bit fields can't be
indexed...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 19:48:17 von Jonathan Wood

Okay, so we're in similar boats there. It just seemed strange to me that it
would seem strange to you to use a small integer to store one of two
possible values.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" wrote in message
news:%23gEDYOSVIHA.5448@TK2MSFTNGP04.phx.gbl...
> "Jonathan Wood" wrote in message
> news:eSpF89MVIHA.4364@TK2MSFTNGP02.phx.gbl...
>
>> "Mark Rae [MVP]" wrote in message
>> news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
>>> "Jonathan Wood" wrote in message
>>> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>>>
>>>>> So, how do you tell the difference between the two genders when you're
>>>>> using a tinyint...?
>>>>
>>>> Not sure I understand the question. As it is, Male is the first option
>>>> so Male == 0 and Female == 1.
>>>
>>> That seems totally unnatural and unintuitive to me...
>>>
>>> When you use char(1), male is 'M' and female is 'F'...
>>>
>>> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
>>> weird...
>>
>> I'm not sure how long you've been programming
>
> LOL! About 30 years or so...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 19:50:15 von Jonathan Wood

How much memory do you think a bit field takes up in a database? Unless many
bit fields are stored contiguosly, packed into bytes, each bit field would
still take up one byte of storage each. So why is it so important to use a
bit field rather than a byte field?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"ThatsIT.net.au" wrote in message
news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...
>
> "Jonathan Wood" wrote in message
> news:eSpF89MVIHA.4364@TK2MSFTNGP02.phx.gbl...
>> Hmm... I'm not sure how long you've been programming but it doesn't seem
>> at all odd to me. At any rate, it's simply used for a couple of
>> calculations and on a report. There will be no queries based on it.
>
>
> if the values are 0 and 1 then you should use bit
> 0 = false
> 1 = true
>
> entred as you would a int
>
> INSERT INTO dataTypes (aBit)Values(1)
>
>
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>> "Mark Rae [MVP]" wrote in message
>> news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
>>> "Jonathan Wood" wrote in message
>>> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>>>
>>>>> So, how do you tell the difference between the two genders when you're
>>>>> using a tinyint...?
>>>>
>>>> Not sure I understand the question. As it is, Male is the first option
>>>> so Male == 0 and Female == 1.
>>>
>>> That seems totally unnatural and unintuitive to me...
>>>
>>> When you use char(1), male is 'M' and female is 'F'...
>>>
>>> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
>>> weird...
>>>
>>>
>>> --
>>> Mark Rae
>>> ASP.NET MVP
>>> http://www.markrae.net
>>
>

Re: Don"t Understand Error Message (Database)

am 12.01.2008 20:04:46 von mark

"Jonathan Wood" wrote in message
news:OxQ32uUVIHA.5508@TK2MSFTNGP04.phx.gbl...

> Okay, so we're in similar boats there. It just seemed strange to me that
> it would seem strange to you to use a small integer to store one of two
> possible values.

Because it's totally the wrong data type for a person's gender! There are no
possible circumstances where the entity of gender (i.e. male / female) can
be considered to be a *numeric* entity unless, perhaps, you are interested
in the number of Y chromosomes... :-)

A smallint is used for *numeric* values ranging from -32,768 to 32,767 and
takes up two bytes - this means that you're using up twice as much storage
as you need to...

It's a basic design issue, really - of course the way you have designed your
schema will work, but it's still wrong...

Similarly, SQL Server has a datetime and smalldatetime datatypes which are
for storing date values. Now, of course, dates *could* be stored in a
varchar or char field, but that would be equally poor design...

Anyway, this is drifting a bit off-topic...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 12.01.2008 21:19:10 von Jonathan Wood

Mark,

> Because it's totally the wrong data type for a person's gender! There are
> no possible circumstances where the entity of gender (i.e. male / female)
> can be considered to be a *numeric* entity unless, perhaps, you are
> interested in the number of Y chromosomes... :-)

Or get a request to add support for an "unspecified" state.

> A smallint is used for *numeric* values ranging from -32,768 to 32,767 and
> takes up two bytes - this means that you're using up twice as much storage
> as you need to...

I already posted that I changed them all to bytes.

> It's a basic design issue, really - of course the way you have designed
> your schema will work, but it's still wrong...
>
> Similarly, SQL Server has a datetime and smalldatetime datatypes which are
> for storing date values. Now, of course, dates *could* be stored in a
> varchar or char field, but that would be equally poor design...

Well, when I consider the following:

1. As near as I can tell, a byte uses the same amount of database storage
that a bit uses.

2. I'm covered if another option was ever requested.

3. More importantly, it simplifies storing the value since I'm getting the
value as an integer (from a CheckBoxList control). I know many will dismiss
this but since I already ran into trouble with errors due to it being a
smallint rather than an int and no one that replied to my original post was
able to correctly identify the reason and I had to resolve it by blinding
trying different things, it's an issue to me.

I'm sticking with a byte and my opinion that it is not wrong or poor design.

You mileage may vary. :-)

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 13.01.2008 01:54:20 von me

"Mark Rae [MVP]" wrote in message
news:emGQJPSVIHA.4440@TK2MSFTNGP06.phx.gbl...
> "ThatsIT.net.au" wrote in message
> news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...
>
>> if the values are 0 and 1 then you should use bit
>
> Unless the field is used in any query criteria, as bit fields can't be
> indexed...
>


How do you mean?

I just made a query against a bit field

>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 13.01.2008 01:54:23 von me

"Jonathan Wood" wrote in message
news:eyC48vUVIHA.5596@TK2MSFTNGP05.phx.gbl...
> How much memory do you think a bit field takes up in a database?

1 bit uses 1 byte

8 bits uses 1 byte


Bit vs. Char(1) - One bit will take up 1 byte, 8 bits will still take up 1
byte, and a char(1) takes 1 byte. It could be argued that using a char(1) to
store Y/N is more readable, but it is far more efficient to use a bit column
if the table contains more than 1 bit column. You'll also eliminate the
possibility of someone trying to put an A/B/C/etc. in the char(1) field,
leading to incorrect data/functionality. Generally, it is considered better
practice to use the bit data type. Even if the table only contains a 1 bit
column, it will allow you to add additional bit columns in the future. There
will be no need to modify the data type/data on the existing char(1) column
in order to take advantage of the optimal data storage configuration.
http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci 1284636,00.html


Unless many
> bit fields are stored contiguosly, packed into bytes, each bit field would
> still take up one byte of storage each. So why is it so important to use a
> bit field rather than a byte field?
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "ThatsIT.net.au" wrote in message
> news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...
>>
>> "Jonathan Wood" wrote in message
>> news:eSpF89MVIHA.4364@TK2MSFTNGP02.phx.gbl...
>>> Hmm... I'm not sure how long you've been programming but it doesn't seem
>>> at all odd to me. At any rate, it's simply used for a couple of
>>> calculations and on a report. There will be no queries based on it.
>>
>>
>> if the values are 0 and 1 then you should use bit
>> 0 = false
>> 1 = true
>>
>> entred as you would a int
>>
>> INSERT INTO dataTypes (aBit)Values(1)
>>
>>
>>>
>>> --
>>> Jonathan Wood
>>> SoftCircuits Programming
>>> http://www.softcircuits.com
>>>
>>> "Mark Rae [MVP]" wrote in message
>>> news:%233apr6MVIHA.4440@TK2MSFTNGP06.phx.gbl...
>>>> "Jonathan Wood" wrote in message
>>>> news:OR0fY3MVIHA.5524@TK2MSFTNGP05.phx.gbl...
>>>>
>>>>>> So, how do you tell the difference between the two genders when
>>>>>> you're using a tinyint...?
>>>>>
>>>>> Not sure I understand the question. As it is, Male is the first option
>>>>> so Male == 0 and Female == 1.
>>>>
>>>> That seems totally unnatural and unintuitive to me...
>>>>
>>>> When you use char(1), male is 'M' and female is 'F'...
>>>>
>>>> A query like SELECT * FROM MyTable WHERE Sex = 0 just seems really
>>>> weird...
>>>>
>>>>
>>>> --
>>>> Mark Rae
>>>> ASP.NET MVP
>>>> http://www.markrae.net
>>>
>>
>

Re: Don"t Understand Error Message (Database)

am 13.01.2008 02:12:58 von me

"Jonathan Wood" wrote in message
news:un95ohVVIHA.3556@TK2MSFTNGP02.phx.gbl...
> Mark,
>
>> Because it's totally the wrong data type for a person's gender! There are
>> no possible circumstances where the entity of gender (i.e. male / female)
>> can be considered to be a *numeric* entity unless, perhaps, you are
>> interested in the number of Y chromosomes... :-)
>
> Or get a request to add support for an "unspecified" state.

why not change them to bits?

I mean lets be honest, I doubt using a int is going to rob you of all your
memory and cause a problem, but if you are going to change to a byte you may
as well change to a bit



>
>> A smallint is used for *numeric* values ranging from -32,768 to 32,767
>> and takes up two bytes - this means that you're using up twice as much
>> storage as you need to...
>
> I already posted that I changed them all to bytes.
>
>> It's a basic design issue, really - of course the way you have designed
>> your schema will work, but it's still wrong...
>>
>> Similarly, SQL Server has a datetime and smalldatetime datatypes which
>> are for storing date values. Now, of course, dates *could* be stored in a
>> varchar or char field, but that would be equally poor design...
>
> Well, when I consider the following:
>
> 1. As near as I can tell, a byte uses the same amount of database storage
> that a bit uses.
>
> 2. I'm covered if another option was ever requested.
>
> 3. More importantly, it simplifies storing the value since I'm getting the
> value as an integer (from a CheckBoxList control). I know many will
> dismiss this but since I already ran into trouble with errors due to it
> being a smallint rather than an int and no one that replied to my original
> post was able to correctly identify the reason and I had to resolve it by
> blinding trying different things, it's an issue to me.
>
> I'm sticking with a byte and my opinion that it is not wrong or poor
> design.
>
> You mileage may vary. :-)
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>

Re: Don"t Understand Error Message (Database)

am 13.01.2008 02:29:14 von mark

"ThatsIT.net.au" wrote in message
news:E100EB50-D8E2-4454-90A9-58750A8C943C@microsoft.com...

>>> if the values are 0 and 1 then you should use bit
>>
>> Unless the field is used in any query criteria, as bit fields can't be
>> indexed...
>
> How do you mean?

The bit datatype is not suitable for indexing, so should not be used for for
fields which are participate in query criteria i.e. WHERE clauses...
http://sqlserver2000.databases.aspfaq.com/can-i-create-an-in dex-on-a-bit-column.html


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 13.01.2008 03:42:19 von nomailreplies

re:
!> How do you mean?
!> I just made a query against a bit field

He said "not indexable"...not "not queryable".
You might run into query efficiency problems if the field isn't indexed.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"ThatsIT.net.au" wrote in message news:E100EB50-D8E2-4454-90A9-58750A8C943C@microsoft.com...
>
> "Mark Rae [MVP]" wrote in message news:emGQJPSVIHA.4440@TK2MSFTNGP06.phx.gbl...
>> "ThatsIT.net.au" wrote in message news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...
>>
>>> if the values are 0 and 1 then you should use bit
>>
>> Unless the field is used in any query criteria, as bit fields can't be indexed...



> How do you mean?
>
> I just made a query against a bit field
>
>>
>> --
>> Mark Rae
>> ASP.NET MVP
>> http://www.markrae.net
>

Re: Don"t Understand Error Message (Database)

am 13.01.2008 05:17:58 von me

"Mark Rae [MVP]" wrote in message
news:uFjQ2OYVIHA.1132@TK2MSFTNGP06.phx.gbl...
> "ThatsIT.net.au" wrote in message
> news:E100EB50-D8E2-4454-90A9-58750A8C943C@microsoft.com...
>
>>>> if the values are 0 and 1 then you should use bit
>>>
>>> Unless the field is used in any query criteria, as bit fields can't be
>>> indexed...
>>
>> How do you mean?
>
> The bit datatype is not suitable for indexing, so should not be used for
> for fields which are participate in query criteria i.e. WHERE clauses...
> http://sqlserver2000.databases.aspfaq.com/can-i-create-an-in dex-on-a-bit-column.html
>


My understanding is you can still query it, but not index it. And as long as
the table is indexed on at least one column other then the bit performance
will be fine.


>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 13.01.2008 05:19:10 von me

"Juan T. Llibre" wrote in message
news:%23gGCu3YVIHA.3452@TK2MSFTNGP03.phx.gbl...
> re:
> !> How do you mean?
> !> I just made a query against a bit field
>
> He said "not indexable"...not "not queryable".
> You might run into query efficiency problems if the field isn't indexed.
>
>

Actualy he said
"Unless the field is used in any query criteria"

but your point is noted.





>
>
> Juan T. Llibre, asp.net MVP
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en español : http://asp.net.do/foros/
> ======================================
> "ThatsIT.net.au" wrote in message
> news:E100EB50-D8E2-4454-90A9-58750A8C943C@microsoft.com...
>>
>> "Mark Rae [MVP]" wrote in message
>> news:emGQJPSVIHA.4440@TK2MSFTNGP06.phx.gbl...
>>> "ThatsIT.net.au" wrote in message
>>> news:B5B73F75-CEC9-4823-8381-AFEBA400D7F5@microsoft.com...
>>>
>>>> if the values are 0 and 1 then you should use bit
>>>
>>> Unless the field is used in any query criteria, as bit fields can't be
>>> indexed...
>
>
>
>> How do you mean?
>>
>> I just made a query against a bit field
>>
>>>
>>> --
>>> Mark Rae
>>> ASP.NET MVP
>>> http://www.markrae.net
>>
>
>

Re: Don"t Understand Error Message (Database)

am 13.01.2008 05:27:10 von Jonathan Wood

ThatsIT.net.au,

>> Or get a request to add support for an "unspecified" state.
>
> why not change them to bits?
>
> I mean lets be honest, I doubt using a int is going to rob you of all your
> memory and cause a problem, but if you are going to change to a byte you
> may as well change to a bit

For the reasons I gave in the post you're replying to. And, for me, a better
question would be "why change them to bits?"

It's working. It's simple. It requires no conversions. And I see absolutely
no downside to the approach I'm taking. You confirmed in your other post
what I suspected: that a byte uses exactly the same amount of space in the
database as a bit does. I'm open to hear about issues anyone still may have
about this, but they need to be specific about what is gained as I don't see
anything to be gained by changing this.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 13.01.2008 13:10:46 von me

"Jonathan Wood" wrote in message
news:%23$CmVyZVIHA.1208@TK2MSFTNGP03.phx.gbl...
> ThatsIT.net.au,
>
>>> Or get a request to add support for an "unspecified" state.
>>
>> why not change them to bits?
>>
>> I mean lets be honest, I doubt using a int is going to rob you of all
>> your memory and cause a problem, but if you are going to change to a byte
>> you may as well change to a bit
>
> For the reasons I gave in the post you're replying to. And, for me, a
> better question would be "why change them to bits?"

Why change to byte?


>
> It's working. It's simple. It requires no conversions. And I see
> absolutely no downside to the approach I'm taking. You confirmed in your
> other post what I suspected: that a byte uses exactly the same amount of
> space in the database as a bit does. I'm open to hear about issues anyone
> still may have about this, but they need to be specific about what is
> gained as I don't see anything to be gained by changing this.
>

No that not correct, a bit uses a bit, 1/8th of a byte. if you have another
Boolean record to keep your ahead. In your case that may not be so, but I
would say that most of the time one would.

As it said the explanation I posted it is still better to use a bit as you
may need to add another bit field later

so knowing that, i would say Why not change to bit?

> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>

Re: Don"t Understand Error Message (Database)

am 13.01.2008 13:41:24 von mark

"ThatsIT.net.au" wrote in message
news:E3D6A745-440B-4DE9-95B2-99192197E6A7@microsoft.com...

>> The bit datatype is not suitable for indexing, so should not be used for
>> for fields which are participate in query criteria i.e. WHERE clauses...
>> http://sqlserver2000.databases.aspfaq.com/can-i-create-an-in dex-on-a-bit-column.html
>
> My understanding is you can still query it, but not index it.

That's correct - which is what I said...

> And as long as the table is indexed on at least one column other then the
> bit performance will be fine.

??? That's simply not the way databases work... E.g.

UserID int
FirstName varchar(30)
Surname varchar(30)
Gender bit

If you inded the Surname column, that will not help one bit when you execute
a query like: SELECT * FROM UserTable WHERE Gender = 0

How could it...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 13.01.2008 21:37:36 von Jonathan Wood

ThatsIT.net.au,

>> For the reasons I gave in the post you're replying to. And, for me, a
>> better question would be "why change them to bits?"
>
> Why change to byte?

Because that is the smallest integer possible. And it also happens to be the
smallest field size as well.

> No that not correct, a bit uses a bit, 1/8th of a byte. if you have
> another Boolean record to keep your ahead. In your case that may not be
> so, but I would say that most of the time one would.

It would be 1 bit field. That's 8 bits. It's not the same as 1/8th of a
byte.

> As it said the explanation I posted it is still better to use a bit as you
> may need to add another bit field later

In fact, I could have up to 8 with the same storage. Big deal. With an
integer value stored in a byte, I could have up to 256 different values.

I already explained why using an integer was more straight forward. If you
got what I said, then you know the reason. If you didn't, then we're
probably just wasting time.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 14.01.2008 17:56:45 von Andrew Morton

Jonathan Wood wrote:

> Not sure I understand the question. As it is, Male is the first
> option so Male == 0 and Female == 1. I tried creating enums for this
> (and the other options) but stupid C# has problems with if (i ==
> sexesMale). Oh well, I can write code that simply tests the value for
> being 0 or 1.

There's an ISO standard for the values:
http://en.wikipedia.org/wiki/ISO_5218

Andrew

Re: Don"t Understand Error Message (Database)

am 14.01.2008 18:19:32 von Jonathan Wood

Heh, well there ya go. The ISO standard for storing the sex would appear to
require a small integer. Oh well, I'm not looking to follow any ISO
standard, but looks like my approach is not unprecedented.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


"Andrew Morton" wrote in message
news:%23qpf%235sVIHA.1164@TK2MSFTNGP02.phx.gbl...
> Jonathan Wood wrote:
>
>> Not sure I understand the question. As it is, Male is the first
>> option so Male == 0 and Female == 1. I tried creating enums for this
>> (and the other options) but stupid C# has problems with if (i ==
>> sexesMale). Oh well, I can write code that simply tests the value for
>> being 0 or 1.
>
> There's an ISO standard for the values:
> http://en.wikipedia.org/wiki/ISO_5218
>
> Andrew
>

Re: Don"t Understand Error Message (Database)

am 14.01.2008 18:35:54 von mark

"Jonathan Wood" wrote in message
news:%23Eq0lGtVIHA.4808@TK2MSFTNGP05.phx.gbl...

> Heh, well there ya go.

I stand corrected.

> The ISO standard for storing the sex would appear to require a small
> integer.

A byte, not a small integer.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 14.01.2008 19:23:10 von Jonathan Wood

Mark,

>> The ISO standard for storing the sex would appear to require a small
>> integer.
>
> A byte, not a small integer.

After programming for 30 years, I'm sure you are well aware that a byte is
an integer type. In the context of 32 and 64-bit integers, I would consider
an 8-bit type to be a small one. Don't you agree?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Don"t Understand Error Message (Database)

am 14.01.2008 19:37:17 von George Ter-Saakov

To go further, everything is an integer in computer world. Even strings are
:).

in SQL
int is 32 bit,
smallint is 16 bit,
byte is 8 bit.

PS: Did not know that there are standards for sex :).

George.


"Jonathan Wood" wrote in message
news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...
> Mark,
>
>>> The ISO standard for storing the sex would appear to require a small
>>> integer.
>>
>> A byte, not a small integer.
>
> After programming for 30 years, I'm sure you are well aware that a byte is
> an integer type. In the context of 32 and 64-bit integers, I would
> consider an 8-bit type to be a small one. Don't you agree?
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>

Re: Don"t Understand Error Message (Database)

am 14.01.2008 19:58:47 von mark

"Jonathan Wood" wrote in message
news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...

> After programming for 30 years, I'm sure you are well aware that a byte is
> an integer type. In the context of 32 and 64-bit integers, I would
> consider an 8-bit type to be a small one. Don't you agree?

http://technet.microsoft.com/en-us/library/ms187745.aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 14.01.2008 20:55:12 von Jonathan Wood

I wasn't referring to specific SQL data type names, if that's what this is
about. I was talking in general terms about using a small integer.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mark Rae [MVP]" wrote in message
news:OLpcA%23tVIHA.4476@TK2MSFTNGP06.phx.gbl...
> "Jonathan Wood" wrote in message
> news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...
>
>> After programming for 30 years, I'm sure you are well aware that a byte
>> is an integer type. In the context of 32 and 64-bit integers, I would
>> consider an 8-bit type to be a small one. Don't you agree?
>
> http://technet.microsoft.com/en-us/library/ms187745.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 14.01.2008 20:55:27 von nomailreplies

Wow! Why did I have to login to Password to see that page ?

To make things a bit clearer, a byte doesn't equal a smallint,
but a tinyint...at least in SQL Server.

In VB.NET, an integer equals 32 bits (VB6's "Long").





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" wrote in message news:OLpcA%23tVIHA.4476@TK2MSFTNGP06.phx.gbl...
> "Jonathan Wood" wrote in message news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...
>
>> After programming for 30 years, I'm sure you are well aware that a byte is an integer type. In the context of 32 and
>> 64-bit integers, I would consider an 8-bit type to be a small one. Don't you agree?
>
> http://technet.microsoft.com/en-us/library/ms187745.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

Re: Don"t Understand Error Message (Database)

am 14.01.2008 20:55:51 von Jonathan Wood

In a way, yes. But, logically, strings are different, as are
floating-point values.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"George Ter-Saakov" wrote in message
news:OiT59xtVIHA.1132@TK2MSFTNGP06.phx.gbl...
> To go further, everything is an integer in computer world. Even strings
> are :).
>
> in SQL
> int is 32 bit,
> smallint is 16 bit,
> byte is 8 bit.
>
> PS: Did not know that there are standards for sex :).
>
> George.
>
>
> "Jonathan Wood" wrote in message
> news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...
>> Mark,
>>
>>>> The ISO standard for storing the sex would appear to require a small
>>>> integer.
>>>
>>> A byte, not a small integer.
>>
>> After programming for 30 years, I'm sure you are well aware that a byte
>> is an integer type. In the context of 32 and 64-bit integers, I would
>> consider an 8-bit type to be a small one. Don't you agree?
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>
>

Re: Don"t Understand Error Message (Database)

am 22.01.2008 10:13:38 von me

"Jonathan Wood" wrote in message
news:eGMwmQiVIHA.4476@TK2MSFTNGP06.phx.gbl...
> ThatsIT.net.au,
>
>>> For the reasons I gave in the post you're replying to. And, for me, a
>>> better question would be "why change them to bits?"
>>
>> Why change to byte?
>
> Because that is the smallest integer possible. And it also happens to be
> the smallest field size as well.
>
>> No that not correct, a bit uses a bit, 1/8th of a byte. if you have
>> another Boolean record to keep your ahead. In your case that may not be
>> so, but I would say that most of the time one would.
>
> It would be 1 bit field. That's 8 bits. It's not the same as 1/8th of a
> byte.
>
>> As it said the explanation I posted it is still better to use a bit as
>> you may need to add another bit field later
>
> In fact, I could have up to 8 with the same storage. Big deal. With an
> integer value stored in a byte, I could have up to 256 different values.

There is only 2 genders not 256


>
> I already explained why using an integer was more straight forward. If you
> got what I said, then you know the reason. If you didn't, then we're
> probably just wasting time.


I know what you sad, but you did not make sense, it is not a numeric
question, there is only 2 answers, not 256



>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>

Re: Don"t Understand Error Message (Database)

am 22.01.2008 10:17:07 von me

"Jonathan Wood" wrote in message
news:%23Eq0lGtVIHA.4808@TK2MSFTNGP05.phx.gbl...
> Heh, well there ya go. The ISO standard for storing the sex would appear
> to require a small integer. Oh well, I'm not looking to follow any ISO
> standard, but looks like my approach is not unprecedented.


actually the question being asked for in the ISO example is asking a
different question with 4 possible results.

>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
>
> "Andrew Morton" wrote in message
> news:%23qpf%235sVIHA.1164@TK2MSFTNGP02.phx.gbl...
>> Jonathan Wood wrote:
>>
>>> Not sure I understand the question. As it is, Male is the first
>>> option so Male == 0 and Female == 1. I tried creating enums for this
>>> (and the other options) but stupid C# has problems with if (i ==
>>> sexesMale). Oh well, I can write code that simply tests the value for
>>> being 0 or 1.
>>
>> There's an ISO standard for the values:
>> http://en.wikipedia.org/wiki/ISO_5218
>>
>> Andrew
>>
>

Re: Don"t Understand Error Message (Database)

am 22.01.2008 10:19:36 von me

Actually every thing in computers is a bit, as all binary is bits "y or n"
"1 or 0"


"Jonathan Wood" wrote in message
news:Ogi$7duVIHA.4868@TK2MSFTNGP03.phx.gbl...
> In a way, yes. But, logically, strings are different, as are
> floating-point values.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "George Ter-Saakov" wrote in message
> news:OiT59xtVIHA.1132@TK2MSFTNGP06.phx.gbl...
>> To go further, everything is an integer in computer world. Even strings
>> are :).
>>
>> in SQL
>> int is 32 bit,
>> smallint is 16 bit,
>> byte is 8 bit.
>>
>> PS: Did not know that there are standards for sex :).
>>
>> George.
>>
>>
>> "Jonathan Wood" wrote in message
>> news:eqRNJqtVIHA.4440@TK2MSFTNGP06.phx.gbl...
>>> Mark,
>>>
>>>>> The ISO standard for storing the sex would appear to require a small
>>>>> integer.
>>>>
>>>> A byte, not a small integer.
>>>
>>> After programming for 30 years, I'm sure you are well aware that a byte
>>> is an integer type. In the context of 32 and 64-bit integers, I would
>>> consider an 8-bit type to be a small one. Don't you agree?
>>>
>>> --
>>> Jonathan Wood
>>> SoftCircuits Programming
>>> http://www.softcircuits.com
>>>
>>
>>
>