| .NET DotNet Forum Index » General Discussion » Nullable Type... |
|
Page 1 of 1 |
|
| Author |
Message |
| Jon... |
Posted: Fri Nov 06, 2009 4:42 am |
|
|
|
Guest
|
Hello all,
I'm trying to do the following:
int my = null ?? Convert.ToInt32(row.Cells[2].Value) as ow.Cells
[2].Value could be null.
Obviously this isn't working.
What's the best way to get a value from the cell into the nullable
int?
Thanks |
|
|
| Back to top |
|
|
|
| Jon... |
Posted: Fri Nov 06, 2009 5:09 am |
|
|
|
Guest
|
On 6 Nov, 14:56, "Scott M." <s-... at (no spam) nospam.nospam> wrote:
Quote: "Jon" <jonmya... at (no spam) gmail.com> wrote in message
news:c8e34b06-75b1-4809-9e8f-efaaf33ed26f at (no spam) f16g2000yqm.googlegroups.com...
Hello all,
I'm trying to do the following:
int my = null ?? Convert.ToInt32(row.Cells[2].Value) as ow.Cells
[2].Value could be null.
Obviously this isn't working.
What's the best way to get a value from the cell into the nullable
int?
Thanks
How about (psuedo code):
Nullable<int> my = null;
if(row.Cells[2].Value != DBNull.value)
{
my = Convert.ToInt32(row.Cells[2].Value);
}
-Scott
Thanks Scott, worked great. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Fri Nov 06, 2009 9:56 am |
|
|
|
Guest
|
"Jon" <jonmyates at (no spam) gmail.com> wrote in message
news:c8e34b06-75b1-4809-9e8f-efaaf33ed26f at (no spam) f16g2000yqm.googlegroups.com...
Quote: Hello all,
I'm trying to do the following:
int my = null ?? Convert.ToInt32(row.Cells[2].Value) as ow.Cells
[2].Value could be null.
Obviously this isn't working.
What's the best way to get a value from the cell into the nullable
int?
Thanks
How about (psuedo code):
Nullable<int> my = null;
if(row.Cells[2].Value != DBNull.value)
{
my = Convert.ToInt32(row.Cells[2].Value);
}
-Scott |
|
|
| Back to top |
|
|
|
|