为什么此LINQ查询无法按预期工作 [英] Why is this LINQ query not working as expected

查看:60
本文介绍了为什么此LINQ查询无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 的visual studio 215 C#网络应用程序2个datepickers和一个Combobox来过滤我的数据。

I have a visual studio 215 C# web application that uses  2 datepickers and a Combobox to filter my data.

我想从SQL数据库中获取与组合框文本相匹配的数据,并且介于两个日期选择器中选择的日期范围之间。 我正在使用这个C#代码:

I want to get the data from the SQL database that matches the combobox text and falls between the date range selected in the 2 datepickers.  I am using this C# code:

using (AfisLogEntities data = new AfisLogEntities())
                {
                    DateTime Date1 = dpReceived1.SelectedDate.Value;
                    DateTime Date2 = dpReceived2.SelectedDate.Value;
                    string strFNumber = cBoxFNumber.SelectedValue;
                    var results = data.tblInField.Where (a => a.FNumber == strFNumber & (a.RecDate >= Date1 & a.RecDate <= Date2));
                    RadGrid1.DataSource = results.ToList().OrderByDescending(a => a.RecDate);
                    RadGrid1.DataBind();
                }

从ASPx控件获取所有正确的数据并运行查询,但不适用日期范围过滤器。 根据我的故障排除工作,看起来这个LINQ查询应该有效。

All the proper data is being obtained from the ASPx controls and the query runs, however it does not apply the date range filter.  From my troubleshooting efforts it appears this LINQ query should work.

有人能看出为什么日期范围不起作用吗?

Can anyone see why the date range is not working?

推荐答案

你应该使用&&对于布尔"AND"运算符(不是单个&,这是一个按位运算符)。
You should be using && for the boolean 'AND' operator (not single &, which is a bitwise operator).


这篇关于为什么此LINQ查询无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆