当前位置:编程学习 > VB >>

vb DTPicker控件

现在我界面上有两个DTPicker空间 取这两个之间的日期好像是between DTPicker1 and DTPicker2
现在我判断数据库中日期字段里的日期在不在这两个日期之间 怎么判断 
数据库是select * from examine_main_table  
regist_date是日期字段的名称 --------------------编程问答--------------------
strsql="select * from examine_main_table where regist_date between '" & DTPicker1 & "' and '" & DTPicker2 & "' " 
--------------------编程问答-------------------- txtSQL1 = "select * from examine_main_table where regist_date between " & Chr(35) & Str(DTPicker1.Value) & "# and #" & Str(DTPicker2.Value) & Chr(35) 


--------------------编程问答-------------------- strSQL="select * from examine_main_table where regist_date < '" & DTPicker1.value & "' or regist_date >'" & DTPicker2.value & "' " 

access 将单引号换成# --------------------编程问答-------------------- 如果日期值有时分秒:

sSQL = "select * from examine_main_table" & _
       " where regist_date < '" & format$(DTPicker1.Value,"yyyy-mm-dd") & "'" & _
        " or regist_date > '" & format$(DTPicker2.Value,"yyyy-mm-dd") & " 23:59:59'"
--------------------编程问答--------------------
引用 1 楼 jhone99 的回复:
VB codestrsql="select * from examine_main_table where regist_date between '"& DTPicker1&"' and '"& DTPicker2&"'"

正解.
1,不是所有的数据库认识#
2,楼主讲了是日期,没时间的。 --------------------编程问答-------------------- 回5F 不是所有的数据库认识#

这点我倒是不清楚, 但我可以知道 ADODB 你没加上 # 的话是达不到目的的.(测试中) --------------------编程问答-------------------- BETEWWEN语句是正解,参考一下这个:http://download.csdn.net/source/1644211 --------------------编程问答-------------------- strsql="select * from examine_main_table where regist_date between ? and ?"
然后用ADO的COMMAND对象把二个?的值传进去.
补充:VB ,  网络编程
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,