我已创建此查询,并希望按文本值和包含OR语句的日期范围进行过滤。我似乎无法使括号正确。我有这个,但它忽略了日期范围。
DateTime Date1 = dpReceived1.SelectedDate.Value;
DateTime Date2 = dpReceived2.SelectedDate.Value;
var strComment = cBoxComments.Text;
var results = data.tblInmates.Where(a => a.comments.Contains(cBoxComments.Text) &&
(((a.RecDate >= Date1 || a.RecDate <= Date2)))).Take(RadGridMax);
RadGrid1.DataSource = results.ToList().OrderByDescending(a => a.RecDate);
RadGrid1.DataBind();
有什么建议吗?
答案 0 :(得分:0)
感谢大家使用我提供的建议,我修复了查询以便现在可以使用。这对我有用。
DateTime Date1 = dpReceived1.SelectedDate.Value;
DateTime Date2 = dpReceived2.SelectedDate.Value;
var strComment = cBoxComments.Text;
var results = data.tblInmates
.Where (a => a.comments.Contains(cBoxComments.Text) &&
a.RecDate >= Date1 && a.RecDate <= Date2)
.Take(RadGridMax);
RadGrid1.DataSource = results.ToList().OrderByDescending(a => a.RecDate);
RadGrid1.DataBind();
我的问题是错误配置的嵌套IF语句。