我想用DTPICKER控件查询SQL数据库中的数据.请问如果查询某个时间段内的数据语句应该怎么写,比如要查询:2008-1-3到2008-1-6之间的.(日期是由DTPICKER控件获取的)
下面是我的代码.
Private Sub Command1_Click()   
Adodc1.RecordSource = "select * from 状态数据 where (时间 like '%" & (DTPicker1.Value) & "%')"
Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
  DataGrid1.Refresh
     If Adodc1.Recordset.EOF Then
        MsgBox "无此记录"
        Text1.Text = ""
      Exit Sub
   End If
小弟刚接触VB一些语句不太明白,希望各位高手指点一下.谢谢~~

解决方案 »

  1.   

    加入两个DTPICKER控件将like该为between  and  
      

  2.   

    Adodc1.RecordSource = "select * from 状态数据 where 时间 '"&  DTPicker1.Value &"' and '"& dtpicker2.value &"'" 
      

  3.   

    Adodc1.RecordSource   =   "select   *   from   状态数据   where   时间  between  '"& DTPicker1.Value   &"'   and   '"&   dtpicker2.value   &"'"   
      

  4.   

    谢谢 LEFTIE,是可以通过,但是还有问题.比如我要查2008-1-4到2008-1-5之间的信息.只显示2008-1-4的信息,但是如果把2008-1-5改为2008-1-6的话就能把2008-1-5的显示出来,但是2008-1-6的又显示不出来了.请问怎么解决呢???
      

  5.   

    用between的话后一个时间要加上23:59:59。
      

  6.   

    = "Select * from 状态数据 where 时间 between '" & _
       DTPicker1.value & "' and '" & _
       DTPicker2.value & " 23:59:59'"
      

  7.   

    Adodc1.RecordSource = "select * from 状态数据 where 时间 >='" & Format(DTPicker1, "yyyy-mm-dd") &   "' And 时间 <'" & Format(DTPicker2 + 1, "yyyy-mm-dd") & "'"