private CriterionItem GetValidCriterionItem() { Field field = (Field)cbField.SelectedItem; Op Op = (Op)cbOperator.SelectedItem; string FValue = txtValue.Text; conjuction cj; string FieldType = field.Type; if (criteriaBuilder.IsFirstItem()) { cj = conjuction.nil; } else { if (rbAnd.Checked) { cj = conjuction.and; } else { cj = conjuction.or; } } switch (FieldType.ToLower()) { case "string": FValue = string.Format("{0}", FValue); break; case "decimal": decimal d; if (!decimal.TryParse(FValue, out d)) { lblMessage.Text = "Please enter a number in the field value"; return(null); } break; case "date": DateTime dd; if (!DateTime.TryParse(FValue, out dd)) { lblMessage.Text = "Please enter a date in the field value"; return(null); } FValue = string.Format("{0}", FValue); //do a date format break; case "like": FValue = string.Format("{0}", FValue); break; } //clean. no error Criterion cr = new Criterion(cj, field.Name, Op, FValue); return(new CriterionItem("index" + index, cr)); }