dbnull.value if clause always reports null

hi, i got this code.

ArrayList list = new ArrayList();

for (int i=0; i < ds.Tables[0].Rows.Count; i++)

{

Tree t = new Tree();

t.Id = (double)ds.Tables[0].Rows[i][0];



if (ds.Tables[0].Rows[i][1] != DBNull.Value)

{

t.Owner = (double)ds.Tables[0].Rows[i][1];

}

else

{

t.Owner = 0;

}



if (ds.Tables[0].Rows[i][6] != DBNull.Value)

{

t.Screenshot = (string)ds.Tables[0].Rows[i][6];

}

else

{

t.Screenshot = "";

}

if (ds.Tables[0].Rows[i][7] != DBNull.Value)

{

t.LeafScreenshot = (string)ds.Tables[0].Rows[i][7]; }

else

{

t.LeafScreenshot = "";

}

list.Add(t);

}

the loop enters the details to Tree obj and then to the list collection.
the problem is that when i got the first null value from ds (dataset),
the Id value is continues to be entered OK but all the other fields (screenshot, owner etc) isn't.
i mean that after the first time of null in the ds , the if clause will always report null.
does anyone got a clue why?
[1289 byte] By [AviLaviad] at [2007-11-19 2:46:53]
# 1 Re: dbnull.value if clause always reports null
I don't believe that it should be working ...

DataRow contains Null values in specific data type. For example Varchar NULL column will be returned as System.Data.SqlTypes.SqlString.Null (not DBNull.Value)

What it will do 4 your code explains some excersises in immediate window:

?System.Data.SqlTypes.SqlString.Null==DBNull.Value
false

?System.Data.SqlTypes.SqlString.Null!=DBNull.Value

true


IMHO U shuld rather use if (!ds.Tables[0].Rows[i].IsNull(1)) syntax instead.

Best regards,
Krzemo.
Krzemo at 2007-11-9 11:45:58 >
# 2 Re: dbnull.value if clause always reports null
welp,
i put IFNULL in the sql query and it solved it.
thanks for your time man.
AviLaviad at 2007-11-9 11:47:00 >