Access数据库,ado连接,数据库有一日期字段里面是类似2002-01-12的格式,用一combobox让用户选择年份,现在象查询日期为2002年的数据我用了这条句子:
   select * from table where 日期=combobox1.text%
但是提示错误,这样的句子该如何写呢?

解决方案 »

  1.   

    sql.add('select * from table1 where year(日期) = '+combobox1.txt);
      

  2.   

    select * from table where 日期=#combobox1.text%#
      

  3.   

    select * from table where 日期=#' +formatdatetime('yyyy-mm-dd',combobox1.text%)+'#'
      

  4.   

    sql.add('select * from table where 日期='+combobox1.text+'%');
      

  5.   

    sql.add('select * from table1 where year(日期) = '+combobox1.txt);
      

  6.   

    select * from table where 日期=#combobox1.text%#
    access中的日期分割符是#所以需要加上
    就像sqlserver中是单引号一样
      

  7.   

    查询日期的时候,ACCESS数据库需要用#把时间前口包起来,如果你是SQL数据库,就用',这再变程序的时候要注意哦。
      

  8.   

    select * from table where 日期=strtodate(组合框中所选内容);
      

  9.   

    应该是select * from table where 日期=#’+combobox1.text+‘#
      

  10.   

    建议你最好是用变量,而不是用combobox1.text;这不是好的习惯。
      

  11.   

    sql.add('select * from table1 where year(日期) = '+combobox1.txt);
      

  12.   

    sql.add('select * from table1 where year(日期) = '+combobox1.text);
      

  13.   

    你到网上去找一本叫做Jet SQL参考的电子书看一看,
    Access的SQL中,日期型数据的分隔符是#,如下:
    insert into tb1 (cn) values (#2004-07-01#)
      

  14.   

    sql.add('select * from table where date=to_date('''+combobox1.text+''','yyyy-mm-dd')');
      

  15.   

    strSQl:='select * from table where 日期=#'+combobox1.text+'#';