简体   繁体   English

仅基于年份选择值类型为DateTime的DataRows

[英]Selecting DataRows with valuetype DateTime based on only year

I need to select a 'DateTime' field from my DataSet based on only the year. 我只需要根据年份从数据集中选择一个“ DateTime”字段。 (To begin with, may expand to year + month later) (一开始可能会扩展到年+月)

The program exits with an error when it is run, and I'm unsure what the real query would be in this case. 该程序在运行时退出并显示错误,我不确定在这种情况下真正的查询是什么。 - I do NOT have access to the database to do it in the query, so it has to be in the DataSet -我无权在查询中访问数据库,因此它必须位于DataSet中

IEnumerable<DataRow> selectedRows = myLicenseInfoDataSet.Tables[0].Select("CreationDate = #" + startDateTime.Year.ToString() + "#");

通过执行以下操作解决了我的问题:

                ICollection<DataRow> selectedRows = myLicenseInfoDataSet.Tables[0].Select("CreationDate >= #" + startDateTime + "# AND CreationDate <= #" + startDateTime.AddYears(1).AddDays(-1) + "#");


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

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