Hi all,
I am wondering if I can do casting for null object. Lets see the following code:
int i;
object o;
o = null;
i = (int)o;
I am getting error that "Object reference not set to an instance of an object."
Is this possible by any other way
Thank you

How to cast Null object.
Heidi
I made one more change to my DbUtility class - maked the method as public. I also marked it as an answer, as I assume it is.
cheers back at ya!
Qwonfu
Hi Blair,
Thanks again.
if I am using with second option of your above example, having following error:
"The as operator must be used with a reference type ('int' is a value type) ".
Regards
Dmitry Titov MSFT
I am thinking you can make a globally available static method:
John7
But see the post I just made above. .. I have made a couple of edits in it. . . make sure you get it now with my latest edits.
Silvia Elena
take a look at nullable types -
Hoot
Thank you very much Blair,
You are too good. I cant express my feeling.
Have a great time.
Cheers.....
SameerM
Ow Nullable types true. I forgot them sorry... :)
Happy coding...
Phillb
Hi Blair,
I am not getting about int .
Actuallu I am getting error while using dataset as following:
for(i=0...............{
int
intModelId = (int)dsTrims.Tables[0].Rows[ i ]["model_id"]; }where "dsTrims" is dataset.
In this code if "model_id" is null then getting error that "casting is not valid".
How can I solve this error without writing lots of code. I can do it by checking like:
if(dsTrims.Tables[0].Rows[ i ]["model_id"] is DBNULL){ ....... }
But I have to write/check this statement for each & every column.
Any other possible way
Thank you
Coolnet1savvy
int is a Nullable Integer
or, if non-nullable int and want DBNull to be int.MinValue:
Grahamrounce