condstr = ""
If Text1.Text <> "" Then
   If condstr = "" Then
      condstr = "日期 like'" + Format(Text1.Text, "yyyy-mm-dd") + "'"
   Else
       condstr = condstr + "and 日期='" + Format(Text1.Text, "yyyy-mm-dd") + "'"
   End If
End IfIf Combo2.Text <> "" Then
    If condstr = "" Then
       condstr = "姓名 like'" + Trim(Combo2.Text) + "'"
    Else
       condstr = condstr + "and 姓名 like'" + Trim(Combo2.Text) + "'"
    End If
  End IfIf condstr <> "" Then
   Adodc1.RecordSource = "select * from t1 where " + condstr
   
   Adodc1.Refresh
   MsgBox Adodc1.Recordset.RecordCount  '当我选择日期来查询时无记录,当选择姓名查询时有记录。当然只要有时间查询就无记录???
   
  Else
   Adodc1.RecordSource = "select * from t1"
   Adodc1.Refresh
  End If
我这两天为这个烦透了,不知为何?请高手帮忙啊?

解决方案 »

  1.   

    那你查询进也要加上时间才可以查询的
    不然就是没记录的,我也刚刚碰到这个事情
    如果你那是一个视图的话,就用Convert函数转化一下就可以了
      

  2.   

    象你这样的情况还是用
    Convert(varchar(10),日期,21) like'" + Format(Text1.Text, "yyyy-mm-dd")
    用这句看看
      

  3.   

    hai,还不能解决??我不是用视图。
      

  4.   

    原来发现我把like换成"="就ok了。
      

  5.   

    access2000
    If Text1.Text <> "" Then
       If condstr = "" Then
          condstr = "日期 like " & Text1.Text & "%"
       Else
           condstr = condstr + "and 日期=#" + Format(Text1.Text, "yyyy-mm-dd") + "#"
       End If
    End If
    如果用likes要帶%,如果用等號,在日期的前後用#sql server2000
    If Text1.Text <> "" Then
       If condstr = "" Then
          condstr = "日期 like'" + Format(Text1.Text, "yyyy-mm-dd") + "'%"
       Else
           condstr = condstr + "and 日期='" + Format(Text1.Text, "yyyy-mm-dd") + "'"
       End If
    End If
      

  6.   

    SQL数据库
    employeepaytable.年月 = '" & 日期 & "'"
    ACCESS数据库
    employeepaytable.年月 = #" & 日期 & "#"
    查询时主要是格式的问题
      

  7.   

    使用LIKE进行查询时,要加上%号,才能支持模糊查询的,如果是日期格式,还必须加上
    #号
      

  8.   

    access和sql查询时在条件的两端家加的标示好象不同
    我原来遇到过
    我照书上 的例子用'
    但实际查询出错
    改为#
    后成了