commstr="select * from psversion where 开始日期<='#2004-07-01#'";commstr="select * from psversion where 开始日期<='"+ Convert.ToDateTime('2004-07-01').date+"'";commstr="select * from psversion where 开始日期<='2004-07-01'";commstr="select * from psversion where 开始日期<='#2004-07-01 12:00:00'";都试过了, 不行呀!

解决方案 »

  1.   

    你那个已经是string型的了,比较的时候不要用#了,直接字符串比较就ok了
      

  2.   

    字段"日期"是ACCESS中的  日期型 的字段
      

  3.   

    commstr="select * from psversion where 开始日期<='"+ Convert.ToDateTime('2004-07-01')+"'";应该将单引号'去掉吧!
      

  4.   

    select * from psversion where TimeBegin<'2004-07-01 12:00:00'在sqlserver数据库中,此语句是通过的。 ACCESS中有什么问题,暂时无从考证。不过有个办法是可以做到的。先用select * from psversion先弄出所有数据。再从DataTable中Remove掉不符合的记录,不过这样总归不很好。access又没有查询分析器,麻烦
      

  5.   

    是呀, select * from psversion where TimeBegin<'2004-07-01 12:00:00', 是可以在SQLServer中通过, 但是在ACCESS中就不行了, ACCESS也没有查询分析器, 不方便,
    如果我把SQL语句改为: Sselect * from psversion 就可以查询出所有的数据了, 现在关键就是怎么去比较日期, 请大家帮忙! 谢谢大家了.
      

  6.   

    那把日期取出来转换成string型比较不行吗?
      

  7.   

    其实在access中你用查询生成器作个时间查询语句然后看他的SQL语句一般都可以的~
      

  8.   

    楼主,我建议你先去你的数据库表中看看那个日期型字段里面的值,看看里面的存储形式是怎么样的。不过我这里都是“commstr="select * from psversion where 开始日期<='2004-07-01'";”这样就可以的!
      

  9.   

    commstr="select * from psversion where 开始日期<='"& Convert.ToDateTime('2004-07-01') &"'";
      

  10.   

    Access没有查询生成器呀, 里面只有一个做查询的工具, 而且也看不到SQL语句.
      

  11.   

    &与+ 不一样吗? 我用一Label.caption查看SQL语句查看commstr, 结果都是一样的呀!
      

  12.   

    试一下这个
    commstr="select * from psversion where 开始日期<="+ Convert.ToDateTime("2004-07-01");
      

  13.   

    commstr="select * from psversion where 开始日期<='"+ Convert.ToDateTime("2004-07-01").ToString("yyyy-MM-dd") +"'";
    这样试一下。或者你这样调试一下,将这条生成的SQL语句放到数据库中运行一下,这样错误比较清楚.
      

  14.   

    我考,我试了一下,不要加"'"就可以了。也就是这样:
    commstr="select * from psversion where 开始日期 < 2004-7-1 ";但是问题来了:我新建了一个access表[date],里面又两个字段begin和end,分别为2000-1-1,2000-3-1。我用"select * from [date] where begin < 2004-7-1 "查不到,用"select * from [date] where begin > 2004-7-1 "反而查到了,怪了!!!!
    大家不信可以试试看。
      

  15.   

    commstr="select * from psversion where 开始日期 < 2004-7-1 ";
    这样不行呀! 查不出什么结果来, 查询的东西为空, 我的DatagriD为空值,
      

  16.   

    这就是我上面说的奇怪的事情了:
    "select * from [date] where begin < 2004-7-1 "查不到,用"select * from [date] where begin > 2004-7-1 "反而能查到。
    你把commstr="select * from psversion where 开始日期 < 2004-7-1 ";改成commstr="select * from psversion where 开始日期 > 2004-7-1 ";试试
      

  17.   

    commstr="select * from psversion where 开始日期 > 2004-7-1 "这样是不行的, 查不出数据来的, 唉看来没办法了, 我有一个朋友给我出了一个主意是在SQL语句中用SQL的Cast函数, 把字符串型转化为日期型的, 但是还是有问题, 现在真是不知道怎么办了, 搞了好几天了, 急死了。
      

  18.   

    ACCESS用#怎么写呀! 是不是这样:
    commstr="select * from psversion where 开始日期 >#2004-7-1#",
    但是我试了试, 不行呀!
      

  19.   

    终于解决了, 谢谢上面的兄弟帮忙, 现在散分, 正确的是:
    commstr="select * from psversion where 开始日期 >#2004-7-1#";
    呵呵!散分了!......