【发布时间】:2020-10-29 21:15:44
【问题描述】:
我有一个包含这些列的 DataTable:
|身份证 |客户 ID |付款金额 | NextScheduleDate |
所有列都包含字符串值(例如,NextScheduleDate 的第 0 行单元格可能是字符串“11/1/2020”)。 我想对其进行过滤并创建一个新的 DataTable,该数据表仅由 NextScheduleDate 值落在日期范围内的行组成。所以用户选择范围,方法应该相应地过滤表格。 某些 NextScheduleDate 单元格值可能为空。 我对 Linq 很陌生,所以非常感谢任何和所有的帮助。到目前为止,这是我的方法,它根本不起作用。
protected void LoadPayments()
{
// User provides textbox values
string startDate = txtStartDateRange.Text;
string endDate = txtEndDateRange.Text;
// This methods gets ALL payments, some of which have already happened
// and some of which are scheduled as future payments
DataTable tblPayments = Payments.GetAllRecurringPayments();
// We only want payments where the NextScheduleDate column value is the range selected by the user
// How to filter so that NextScheduleDate is in between startDate and endDate?
// (Needs to return values where startDate > NextScheduleDate > endDate
DataTable futurePayments = tblPayments.AsEnumerable()
.Where(r => r.Field<string>("NextScheduleDate") == ?????)
.CopyToDataTable();
// Bind
grdPayments.DataSource = futurePayments;
grdPayments.DataBind();
}
【问题讨论】:
-
.Where(r => r.Field
("NextScheduleDate") == DateTime.Now)