access数据库中,字段thedate是日期类型,theTime是c#中DateTime类型的变量,我想查询出日期大于theTime的前100条记录,例如:
SELECT TOP 100 * FROM tableName WHERE thedate > #" + theTime + "# ORDER BY thedate"
上面的查询语句得不到想要的结果,应该怎么写呢?谢谢!

解决方案 »

  1.   

    SELECT TOP 100 * FROM tableName WHERE datediff('d',thedate ,'"+theTime+"')>=0 ORDER BY thedate"
    这样试试
      

  2.   

    SELECT TOP 100 * FROM tableName WHERE thedate > #" + theTime + "# ORDER BY thedate这样写没问题呀,,你说得不到想要的结果,这个查询查的内容有什么不对的?
      

  3.   

    引发异常:已引发:“标准表达式中数据类型不匹配。"去掉TOP条件或者去掉thedate > #" + theTime + "# 条件,就能通过。我试过,这两个条件同时使用就出错
      

  4.   

    对于theTime < thedate的条件,datediff 怎么写呢?
      

  5.   

    你用这个试一下
    SELECT TOP 100 * FROM tableName WHERE datediff('d',thedate ,'"+theTime+"')>=0 ORDER BY thedate"