Tuesday, May 21, 2013

How to handle when database is returning null value

When we are trying to retrieve some thing from database there is a chance of returning null value so at that time we have to check whether it is returning null value or not like...i.e...



 if (dt.Rows[0][0] == DBNull.Value) //we have to check like this weather returning any null value
            {
                homeobj.status = 0;
            }
            else  //if not returning any null value
            {
                homeobj.status = Convert.ToInt32(dt.Rows[0][0]);
            }

No comments:

Post a Comment