通过两个datatimepicker被选中的状态来确定时间查询数据
有两个datatimepicker,组合起来的ShowCheckBox有四种情况:
1.datatimepicker1.ShowCheckBox = FalseAnd datatimepicker2.ShowCheckBox = False
2.datatimepicker1.ShowCheckBox = False And datatimepicker2.ShowCheckBox = True
3.datatimepicker1.ShowCheckBox = True And datatimepicker2.ShowCheckBox = False 4.datatimepicker1.ShowCheckBox = True And datatimepicker2.ShowCheckBox = True
用通过判断这四种情况查询ACCESS中的数据:
当为第1种情况时,查询所有时间序列的数据
当为第2种情况时,查询在 datatimepicker2.value之前时间序列的数据
当为第3种情况时,查询在 datatimepicker1.value之后时间序列的数据
当为第4种情况时,查询在 datatimepicker1.value和datatimepicker2.value之间时间序列的数据
[解决办法]
要用 checked来判断,不能用ShowCheckBox,
Dim sql As String
If (DateTimePicker1.Checked = False And DateTimePicker2.Checked = False) Then
sql = "select * table"
ElseIf (DateTimePicker1.Checked = False And DateTimePicker2.Checked = True) Then
sql = "select * table where dtime< # " & DateTimePicker2.Value & "#"
ElseIf (DateTimePicker1.Checked = True And DateTimePicker2.Checked = False) Then
sql = "select * table where dtime> # " & DateTimePicker1.Value & "#"
ElseIf (DateTimePicker1.Checked = True And DateTimePicker2.Checked = True) Then
sql = "select * table where dtime between # " & DateTimePicker1.Value & "# and # " & DateTimePicker1.Value & "#"
End If