DBNull.value inside IF clause always report 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?