我用query1查询某一段时间内库存量,起史时间分别由两个combobox输入?代码如下:
if (combobox1.text)<>'' and (combobox2.text)<>'' then
begin
query1.close;
query1.sql.clear;
query1.sql.add('select *from abc where date between '''+combobox1.text+''' and '''+combobox2.text+'''');
query1.execsql;
query1.open;
end;
以上的语句是不是有问题啊为什么总是出现operator not applicable to this operand type这样的信息啊?郁闷啊?不知道怎么修改?请各位大侠帮帮小第吧

解决方案 »

  1.   

    首先佩服搂主的精神:在夜里02:51:05还在干活呀!!!
    date字段是日期型吗?
    什么数据库?
    如果是access则在时间前后加 # 如:#2005-01-04#
      

  2.   

    query1.execsql;
    query1.open;->
    query1.active:=true;再检查sql语句有无问题!
      

  3.   

    combobox1.text类型不匹配啊,
    你需要的时间类型的数据
      

  4.   

    'select *from abc where date between '''+combobox1.text+''' and '''+combobox2.text+''''
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'select * from abc where date between '''+combobox1.text+''' and '''+combobox2.text+'''''select * from abc where date between #'+combobox1.text+'# and #'+combobox2.text+'#'
      

  5.   

    如果是access则在时间前后加 # 如:#2005-01-04#
    还有如果query1.sql.add('select *from abc where date between '''+combobox1.text+''' and '''+combobox2.text+'''');
    改为query1.sql.add('select * from abc where date between '''+trim(combobox1.text)+''' and '''+trim(combobox2.text)+'''');
     试试
      

  6.   

    combobox1.tex和combobox2.text值是日期格式就可以if (combobox1.text)<>'' and (combobox2.text)<>'' then
     with query1 do
          begin 
            close;
            sql.clear;
            sql.add('select * from abc where  datebetween '''+combobox1.text+
                    ''' and '''+combobox2.text+'''');
            open;
          end;
          
        execSQL是不返回值的,应该去掉
      

  7.   

    if trim(combobox1.text)<>'' and trim(combobox2.text)<>'' then
    begin
    query1.close;
    query1.sql.clear;
    //*from 改成* from 
    query1.sql.add('select * from abc where date between '''+combobox1.text+''' and '''+combobox2.text+'''');//用strtodatetime(combobox1.text)
    query1.execsql;//一下两句只要一句
    query1.open;
    end;
      

  8.   

    高手还是不行啊我用的是DELPHI自带的数据库paradox,我已经把date这个字段设成datetime了,为什么还是不行啊
    我的思想是想通过6个COMBOBOX来选择年月日,根据起始的年月日和终止的年月日来查询库存的
      

  9.   

    以上的大哥们!你有没有想过啊,Combobox中的text值是string类型的啊,
    而date是datetime类型的,不用转换可以吗???
    可以将Combobox1的值转化成类型后赋给变量date1,将Combobox2的值转换成日期类型后赋给Date2
    再用sql语句的between来实现区间查询!
      

  10.   

    又是Paradox数据库,呵呵,将日期格式转换为美国格式mm/dd/yyyy就能查到了。
    为什么用6个COMBOBOX选择年月日,用DateTimePicker不好吗?query1.close;
    query1.sql.clear;
    query1.sql.add('select * from abc where date >= '''+FormatDateTime('mm/dd/yyyy',DateTimePicker1.Date)+''' and  <='''+FormatDateTime('mm/dd/yyyy',DateTimePicker2.Date)+'''');
    query1.execsql;
    query1.open;
      

  11.   

    另外用Open方式打开,不要用ExecSQL
      

  12.   

    我的思想是想通过6个COMBOBOX来选择年月日======================================================????搞错没有啊?
    强烈建议你用datetimepicker控件
      

  13.   

    query1.close;
    query1.sql.clear;
    query1.sql.add('select * from abc where FormatDateTimeConvert(nvarchar(10),date, 20)>=:P1 and Convert(nvarchar(10),date, 20)<=:P2');
    Parameters.ParamByName('P1').Value := formatdatetime('yyyy-MM-dd',DateTimePicker1.Date);
    Parameters.ParamByName('P2').Value := formatdatetime('yyyy-MM-dd',DateTimePicker2.Date);
    query1.execsql;
    query1.open;
      

  14.   

    最好是用FormatDateTimeConvert转化成标准时间
    不然有些时候找不出来
      

  15.   

    我前几天也碰到这样的问题,你可以参考一下以下的格式:
    SELECT *
    FROM code
    where dt between #2004-11-1# and #2005-1-1#
      

  16.   

    用formatdatetime转换就成了
    还有这个地方
    query1.execsql;
    query1.open;
    ……
    我只能说一句:I服了you!
      

  17.   

    paradox数据库中类型为D的日期字段怎么查询呢? 
    http://community.csdn.net/Expert/topic/3508/3508537.xml?temp=5.419558E-02
      

  18.   

    query1.close;
    query1.sql.clear;
    query1.sql.add('select * from abc where FormatDateTimeConvert(nvarchar(10),date, 20)>=:P1 and Convert(nvarchar(10),date, 20)<=:P2');
    Parameters.ParamByName('P1').Value := formatdatetime('yyyy-MM-dd',DateTimePicker1.Date);
    Parameters.ParamByName('P2').Value := formatdatetime('yyyy-MM-dd',DateTimePicker2.Date);
    ===========================
    query1.execsql;
    query1.open;   这里需要这么多麽?
    ==================================