我想查询一段时间的数据
代码:m_sqlStr.Format(_T("select * from table1 where 时间  between '2011-06-01' and  '2011-08-01'"));
但是查询出来的时候记录集是空的。ACCESS 数据库中的时间类型改成文本,时间 都不可以。我在添加数据的时候是通过获取时间控件的时间值添加进去的。m_dateTime.GetTime(m_time);
m_strTime.Format(_T("%d-%d-%d" ),m_time.GetYear(),m_time.GetMonth(),m_time.GetDay());m_list.InsertItem(0,m_strTime);//插入行m_dataMember.m_pRecord->PutCollect("时间",_bstr_t(m_strTime)); 不知道是哪点出错了,望大家能帮我看一下

解决方案 »

  1.   

    时间应该是要转换的,to_date是oracle里的字符串转换成日期的函数
    access里具体怎么转换,你可以查查相关资料
      

  2.   

    如果你的数据库字段的类型是时间,在access中:
    select * from table1 where 时间 between #2011-06-01# and #2011-08-01#
      

  3.   

    如果你的数据库字段的类型是时间,在access中:
    select * from table1 where 时间 between #2011-06-01# and #2011-08-01#楼上的正解,谢谢。但是现在我要把具体的时间改成时间控件中的变量 该如何了?
      

  4.   

    m_dataMember.m_pRecord->PutCollect("时间",_bstr_t(m_strTime));貌似vc里是直接变成DATE类型,不是_bstr_t吧。我用ADO做的,是直接DATE类型的。
      

  5.   

    问题已经解决,感谢各位!现在我放出正确答案。
    timeStrBack.Format(_T("%d-%d-%d" ),m_Tback.GetYear(),m_Tback.GetMonth(),m_Tback.GetDay());
    timeStrFront.Format(_T("%d-%d-%d" ),m_Tfront.GetYear(),m_Tfront.GetMonth(),m_Tfront.GetDay());
    m_sqlStr.Format(_T("select * from table1 where 时间  between #%s# and  #%s#"),timeStrFront,timeStrBack);