Re: Nullable types giving error
- From: "tshad" <tfs@xxxxxxxxxxxxxx>
- Date: Sat, 23 Feb 2008 22:58:44 -0800
"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message
news:47bf71e2$0$90263$14726298@xxxxxxxxxxxxxxxxxx
tshad wrote:
It depends. The type in SQL is tinyint. In my record fn.ProjectTableID^^^^^^^^^^^
is an "int?". The value will either be null or a number from 1-25.
If it is null, which is the case for the first 12 records, I get the
following in the debugger watch window
{Name = "DBNull" FullName = "System.DBNull"} System.Type
{System.RuntimeType}
:If it is a value like 10, I get:
{Name = "Byte" FullName = "System.Byte"} System.Type {System.RuntimeType}
I would assume that I would be casting it to either int? or int since I
am putting it in an int? field. I can't change the fn.ProjectTableID to
int (or byte) as it can be null and I need to keep track of that.
Try cast it to byte.
That works fine.
Since a tinyint ranges from 0 to 255, I assume that is why it is assumed to
be a byte.
fn.ProcessingType = dbReader["ProcessingType"] == DBNull.Value ? null :
(byte?)dbReader["ProcessingType"];
This works ok
I would have assumed that int would also work but I guess not.
Thanks,
Tom
Arne
.
- Follow-Ups:
- Re: Nullable types giving error
- From: Arne Vajhøj
- Re: Nullable types giving error
- From: Jon Skeet [C# MVP]
- Re: Nullable types giving error
- References:
- Nullable types giving error
- From: tshad
- Re: Nullable types giving error
- From: Jon Skeet [C# MVP]
- Re: Nullable types giving error
- From: tshad
- Re: Nullable types giving error
- From: Arne Vajhøj
- Nullable types giving error
- Prev by Date: Understanding IoC and Dependency Injection.
- Next by Date: Re: TreeView 2.0 Help Please - Petzold Code Included
- Previous by thread: Re: Nullable types giving error
- Next by thread: Re: Nullable types giving error
- Index(es):
Relevant Pages
|