我在程序中用四个DTPICKER控件实现年月日时分秒的精确查找。请问下面的语句为什么不能按年月日+时分秒的方式精确查找数据呢?
strsql = "select * from invoice where qtime between cdate('" & dtpicker1.Value & +&dtpicker2.value&"') and cdate('" & dtpicker3.Value &+*dtpicker4.value& "')"
strsql = "select * from invoice where qtime between cdate('" & dtpicker1.Value & +&dtpicker2.value&"') and cdate('" & dtpicker3.Value &+*dtpicker4.value& "')"
cmd.CommandText = "select * from abc where z between '" & CDate(DTPicker1.Value) & " " & CDate(DTPicker2.Value) & "' and '" & CDate(DTPicker3.Value) & " " & CDate(DTPicker4.Value) & "'"ACCESS数据库里面的设置是时间日期格式。
VB里面的DTPICKER控件格式设置的是:
DTPicker1.Format = dtpCustom
DTPicker2.Format = dtpCustom
DTPicker1.CustomFormat = "yyyy-MM-dd "
DTPicker2.CustomFormat = "tt:HH:mm:ss"
DTPicker3.Format = dtpCustom
DTPicker4.Format = dtpCustom
DTPicker3.CustomFormat = "yyyy-MM-dd "
DTPicker4.CustomFormat = "tt:HH:mm:ss"
cmd.CommandText = "select * from abc where z between #" & CDate(DTPicker1.Value) & " " & CDate(DTPicker2.Value) & "# and #" & CDate(DTPicker3.Value) & " " & CDate(DTPicker4.Value) & "#"
cmd.CommandText = "select * from abc where z between '" & Format(DTPicker1.Value, "yyyy-mm-dd") & " " & Format(DTPicker2.Value, "am/pm:HH:mm:ss") & "' and '" & Format(DTPicker3.Value, "yyyy-mm-dd") & " " & Format(DTPicker4.Value, "am/pm:HH:mm:ss") & "'"
cmd.CommandText = "select * from abc where z between #" & CDate(DTPicker1.Value) & " " & CDate(DTPicker2.Value) & "# and #" & CDate(DTPicker3.Value) & " " & CDate(DTPicker4.Value) & "#"
select * from tablename 日期字段 between #2012-12-1# and #2012-12-31#
数据库为SQL的,查询日期型字段的方法:
select * from tablename 日期字段 between '2012-12-1' and '2012-12-31'