我有一个dt
包含两列FromDate
和ToDate
. 我有两个文本框,我在其中输入日期blackOutFromDate
和blackOutToDate
. 说,我的 DataTable 中有 7 行dt
:
From Date To Date
8/21/2012 To 8/22/2012
8/23/2012 To 8/24/2012
8/25/2012 To 8/25/2012
8/5/2012 To 8/6/2012
8/26/2012 To 8/27/2012
8/1/2012 To 8/2/2012
8/3/2012 To 8/3/2012
如果我在文本框中输入的值CheckInDate
介于CheckOutDate
DataTable 的任何匹配日期范围之间dt
,它应该返回具有此类匹配的行数的计数。
我在做
foundRows = _blackOutTable.Select
(
"(FromDate <='" +
blackOutFromDate.ToShortDateString() + "' AND ToDate >= '" +
blackOutFromDate.ToShortDateString() + "')"
+ "OR (FromDate <='" +
blackOutToDate.ToShortDateString() + "' AND ToDate >='" +
blackOutToDate.ToShortDateString() + "')"
+ "OR (FromDate >='" +
blackOutFromDate.ToShortDateString() + "' AND FromDate <='" +
blackOutToDate.ToShortDateString() + "')"
+ "OR (ToDate >= '" +
blackOutFromDate.ToShortDateString() + "' AND ToDate <='" +
blackOutToDate.ToShortDateString() + "')"
);
if (foundRows.Length == 0)
{
}
编辑:我将在 SQl 服务器中归档的 DateFrom 和 DateTo 存储为
CAST(MONTH(date1) AS VARCHAR(2)) + '/' + CAST(DAY(date1) AS VARCHAR(2)) + '/' +
CAST(YEAR(date1) AS VARCHAR(4)) [fromdate],
CAST(MONTH(date2) AS VARCHAR(2)) + '/' + CAST(DAY(date2) AS
VARCHAR(2)) + '/' + CAST(YEAR(date2) AS VARCHAR(4)) [todate]
blackOutFromDate 和 blackOutFromDate 属于 DateTime 类型。
但它没有返回正确的值。选择表达式存在一些问题。我能做些什么来解决这个问题?