数据表选择大于日期

时间:2015-11-10 18:04:49

标签: vb.net datatable

我已经用MySQL数据填充了一个数据表,我需要从数据表中检索所有记录,其中“unitassign”是DBNull并且“putime”(MySQL日期时间格式)大于或等于今天的日期(即使时间已经过去了)和“putime”(同一个变量)小于或等于vbdatetime变量“eighthr”(这个将根据日期和时间进行匹配)

Dim eighthr As DateTime
If (DateTime.Now.AddHours(8).ToString("yyyy-MM-dd") = Date.Now.ToString("yyyy-MM-dd")) Then
    eighthr = CDate(DateTime.Now.ToString("yyyy-MM-dd"))
Else
    eighthr = DateTime.Now.AddHours(8)
End If
resultstr = "unitassign is Null AND (putime >= #" & SchedulerControl1.Start.ToString("yyyy-MM-dd") & "# AND putime <= #" & eighthr & "#)"

Dim result() As DataRow = jboardtable.Select(resultstr)

虽然我的数据表中的行应该出现

,但是没有返回结果

1 个答案:

答案 0 :(得分:0)

尝试:

Dim eighthr As DateTime
If DateTime.Now.TimeOfDay.TotalHours < 16 Then
    eighthr = DateTime.Now.Date
Else
    eighthr = DateTime.Now.Date.AddDays(1)
End If
resultstr = "unitassign is Null AND (putime >= #" & SchedulerControl1.Start.ToString("yyyy-MM-dd") & "# AND putime <= #" & eighthr & "#)"
Dim result() As DataRow = jboardtable.Select(resultstr)