如何用DTPicker设置时间段查询?
它怎么老是有问题啊?
说是FROM 语句出错.Private Sub Command4_Click()
Adodc4.RecordSource = "select * from 年检表 where 年检时间>='" & CDate(Me.DTPicker1.Value) & "' and VDate<='" & CDate(Me.DTPicker2.Value) & "'"
Adodc4.Refresh
 End Sub
的错误信息是
参数类型不正确,或不在可接受范围之内,或与其他参数冲突

解决方案 »

  1.   

    用#代替'
    Adodc4.RecordSource = "select * from 年检表 where 年检时间>=#" & CDate(Me.DTPicker1.Value) & "# and VDate<=#" & CDate(Me.DTPicker2.Value) & "#"
      

  2.   

    还有一种方法是在确保用户输入的DTPicker1.Value的值是有效日期类型后,直接用
    Adodc4.RecordSource = "select * from 年检表 where 年检时间>='" & (Me.DTPicker1.Value) & "' and VDate<='" & (Me.DTPicker2.Value) & "'"
      

  3.   

    Adodc4.RecordSource = "select * from 年检表 where 年检时间>=#" & Format(Me.DTPicker1.Value,"yyyy-mm-dd") & "# and VDate<=#" & Format(Me.DTPicker2.Value,"yyyy-mm-dd") & "#"
      

  4.   

    ACCESS用#號,SQL Server用單引號,
    這會給程序的升級帶來麻煩。SQL語句應該這樣寫:
    select * from Table where Date between ? and ?
    然後把二個問號的值傳進去,就不存在#號、單引號的問題,
    也防止了SQL漏洞。