简体   繁体   English

我对此LINQ查询做错什么(查询数据表)

[英]What am I doing wrong with this linq query (querying datatable)

I am connecting my Windows Form app to their Access DB (ugh, I know), and cannot get my linq query to return anything. 我将Windows Form应用程序连接到他们的Access数据库(我知道,哦),但无法获取linq查询以返回任何内容。

var matchDateField = from myRow in boilerDT.AsEnumerable()
                     where myRow.Field<DateTime>("EntryDate").ToShortDateString() == dateTimePicker1.Value.ToShortDateString()
                     select myRow;

Any suggestions? 有什么建议么?

Get all the rows: 获取所有行:

IEnumerable<DataRow> dateFieldQuery =
                    from myRow in boilerDT.AsEnumerable()
                    select myRow;

Filter by date: 按日期筛选:

IEnumerable<DataRow> matchDateField =
                dateFieldQuery.Where(p => p.Field<DateTime>("EntryDate").Date == dateTimePicker1.Value);

So here you're using deferred execution which enables multiple queries to be combined or a query to be extended. 因此,这里您使用的是延迟执行,该执行使多个查询可以合并或扩展查询。 When a query is extended, it is modified to include the new operations, and the eventual execution will reflect the changes. 扩展查询时,会将其修改为包括新操作,最终执行将反映这些更改。

The first query returns all the rows and the second query extends the first by using Where to return all the rows with specific date. 第一个查询返回所有行,第二个查询通过使用Where返回具有特定日期的所有行来扩展第一个查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM