We help IT Professionals succeed at work.

Checking for null value?

sbornstein2
sbornstein2 asked
on
Hello all.  How do I ensure that if a dataset field is null I dont want to try and set it?  I thought it was just != null but that is not working.  However, I could swear that works in the later frameworks.  In 1.1 I have the following which the field is null but it still gets into the next line of code:

if (dsOrderDetail.Tables[0].Rows[0]["OrderTotal"] != null)
{  //field is null but it still gets into this code
}
Comment
Watch Question

Software Architect
CERTIFIED EXPERT
Top Expert 2008
Commented:
you can do as:

if (!Convert.IsDBNull(dsOrderDetail.Tables[0].Rows[0]["OrderTotal"])
{
}

Commented:
if (equals(dsOrderDetail.Tables[0].Rows[0]["OrderTotal"],Dbnull.value)!=true)
{  
}

Author

Commented:
do you know if what I had here works possibly in the later versions?
Rahul Goel ITILSenior Consultant - Deloitte
CERTIFIED EXPERT

Commented:
if (!Convert.IsDBNull(dsOrderDetail.Tables[0].Rows[0]["OrderTotal"])
{
}
Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
@Rahu,
have you read the previous answers?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.