I am trying to use code to use a CAML query to pull data from a list...when I iterate through the data returned by my query and try to assign them to variables in my code, I get some nullException when the fields in the list have no data (null). What would be the recommended way to get my variables to return just an empty string, if there is blank data returned for any field in from my list. Here is what my snippet looks like...so right now when there is no data from the list, my field variables are throwing a null exception. How can I get them to hold a whitespace (blank)? Or get past this exception?
SPList myList = currentWeb.Lists["MyListName"];
SPQuery query = new SPQuery();
query.Query = @"";
SPListItemCollection myCollection = mydList.GetItems(query);
foreach (SPListItem item in myCollection)
{
string field1 = item["fieldone"].ToString();
string field2 = item["fieldtwo"].ToString();
string field3 = item["fieldthree"].ToString();
string field4 = item["fieldfour"].ToString();
}