strRstConn = "select * from tbl_abc where b_Date=cdate(2011-6-29)"
rstTemp.Open strRstConn, CnnDB, adOpenStatic, adLockPessimistic
If rstTemp.EOF = True And rstTemp.BOF = True Then
    MsgBox "日期为【" & dtpRecDate.Value & "】的单据都已经打印!" & vbCrLf & "或无单据。", vbInformation, "打印单据"
Else
    If rstTemp.Fields("b_Check") = 1 Then
        MsgBox "单据已打印,不能再次打印!", vbInformation, "打印单据"
        ......上面代码中的b_date字段在数据库中是日期型的,使用的cdate也没问题,
可是当b_date存储的值就是2011-6-29这个日期时,查询的结果还是为空的,
也就是说无论何时,eof与bof属性都为真。
不知为何,请高人指点。我试过用convert,提示是“函数convert未定义”
我访问的数据库是access2007,程序是VB6.0

解决方案 »

  1.   

    select * from tbl_abc where cdate(b_Date)='2011-6-29'"
      

  2.   

    strRstConn = "select * from tbl_abc where b_Date='2011-6-29'"
    rstTemp.Open strRstConn, CnnDB,adopenkeyset,adlockreadonly
    If rstTemp.recordcount=0 Then
        MsgBox "日期为【" & dtpRecDate.Value & "】的单据都已经打印!" & vbCrLf & "或无单据。", vbInformation, "打印单据"
    Else
        If rstTemp.Fields("b_Check") = 1 Then
            MsgBox "单据已打印,不能再次打印!", vbInformation, "打印单据"
      

  3.   

    access2007 中
    # ‘2011-6-29’# 表示时间,最好加#号
    strRstConn = "select * from tbl_abc where cdate(b_Date)=cdate(# ‘2011-6-29’#)"
    这样试试
      

  4.   

    strRstConn = "select * from tbl_abc where b_Date between '2011-06-28' and '2011-06-30'"数据库中的b_Date是不是包含了时分秒啊?
      

  5.   

    b_Date格式化一下什么数据库?
      

  6.   


    select * from tbl_abc where datediff(day,b_date,'2011-06-28') = 0  你试试这样的语句,如果还出错误提示,那么就说明你的b_Date字段的数据有问题。
      

  7.   

    strRstConn = "select * from tbl_abc where format(b_Date,'yyyy-mm-dd')='2011-06-29'"