sql1 = DTPicker1.Value
sql2 = DTPicker2.Value
sql3 = " AND 商铺号='" & Text1.Text & "'"
sql = "select count(商铺号) 'chs' from 投诉表 where 1=1" & sql3 & "and 投诉日期 > = " & sql1 & " and 投诉日期 < =" & sql2或
sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1" & sql3 & " and 投诉日期  between " & sql1 & " and " & sql2
数据库中有符合的记录,为什么我这写查不出结果呢。

解决方案 »

  1.   

    看sql 的值
    看sql语句是什么样,直接用sql工具查询,是否能查出结果
      

  2.   

    sql已经赋值,但没有打开。
    dim rs  As ADODB.Recordset
    Dim sql As String
    dim sql1 as string
    dim sql2 as string
    dim sql3 as string
    sql1 = DTPicker1.Value 
    sql2 = DTPicker2.Value 
    sql3 = " AND 商铺号='" & Text1.Text & "'" 
    sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1" & sql3 & " and 投诉日期  between " & sql1 & " and " & sql2 
    Set rs = ExecuteSQL(sql).....
    ''''''''''''''''''''''''''''''''''''''
    使用executesql要引用ado2.0以上....
      

  3.   

    谢谢楼上的两位,不过问题还是没有解决,我觉得问题好像是出在那个日期格式上面或者是 between……and……上面。
      

  4.   

    投诉日期 > = '" & format(sql1,"yyyy-MM-dd") & "' "注意红色的
      

  5.   

    '数据库为SQL:
    sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1 " & sql3 & " and 投诉日期  between '" & sql1 & "' and '" & sql2 & &"'"
    '数据库为ACCESS:
    sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1 " & sql3 & " and 投诉日期  between #" & sql1 & "# and #" & sql2 & &"#"
     
      

  6.   

    '是不是数据库中保存了日期与时间?
    '数据库为SQL:
    sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1 " & sql3 & " and 投诉日期  between '" & sql1 & " 00:00:01' and '" & sql2 & &" 23:59:59'"
    '数据库为ACCESS:
    sql = "select 商铺号,业主,处理结果,投诉内容,备注 from 投诉表 where 1=1 " & sql3 & " and 投诉日期  between #" & sql1 & " 00:00:01# and #" & sql2 & &" 23:59:59#"