I am working on a project in Windows Forms designed to record brew history of a brewery. I've got everything basically right but I cant quite figure out how to search brew logs based off of variable criteria. The user should be able to search brew logs from recipe, brewer, date or any combination of these. I am having trouble figuring out how to get the app to recognize what fields are empty when a search is executed. I keep getting a NullReferenceException. I'm pretty sure I understand why this is being thrown but I do not know how to remedy it. Here is the method from which the error is being thrown:
public string criteriaSort()
{
string recipe = recipeCriteria.SelectedItem.ToString();
string brewer = brewerCriteria.SelectedItem.ToString();
string date = dateCriteria.Text;
string result = "";
if (recipe != null && brewer == null & date == null)
{
result = getResults(recipe);
return result;
}
else if (recipe == null && brewer != null & date == null)
{
result = getResults(brewer);
return result;
}
else if (recipe == null && brewer == null & date != null)
{
result = getResults(date);
return result;
}
else if (recipe != null && brewer != null && date == null)
{
result = getResults(recipe, brewer);
return result;
}
else if (recipe != null && brewer == null & date != null)
{
result = getResults(recipe, date);
return result;
}
else if (recipe == null && brewer != null && date != null)
{
result = getResults(brewer, date);
return result;
}
else
{
result = getResults(recipe, brewer, date);
return result;
}
}
Thanks in advance! I should add that the recipe and brewer fields are combo boxes and the date field is a text box.