Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Checking for nullness in SPItem Field

  Asked By: Lacy    Date: Oct 12    Category: Sharepoint    Views: 1139

newbie I can't seem to find an answer for this.

I am trying to check to see if the field I am trying to get data from
in a SPList item is null before trying to access the field.

item["fieldname"] != null or item[index] != null does not seem to
work. In fact when I try to check nullness this way I get the
following error:

Object reference not set to an instance of an object.

I've tried to also use:

System.Type.Missing.Equals(item["fieldname"])

This seems to work in an if statement if I then append the contents of
the field to a StringBuilder (these are all string values), but when I
try to check the emptyness of the string (using
string.IsNullOrEmpty(item["fieldname"].ToString().Trim()) I again get:

Object reference not set to an instance of an object.

So what is the accepted practice for checking to see if a field is
null and checking to see if a field contains an empty string?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Anuj Lakhe     Answered On: Oct 12

Try item["fieldname"] != system.DBNull

 
Didn't find what you were looking for? Find more on Checking for nullness in SPItem Field Or get search suggestion and latest updates.




Tagged: