Nullable Type

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

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
 
Jon said:
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
 
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?

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
Top