代码如下为什么下面的时间比较总是错误的呢?提示 “参数类型不正确 或不在可以接受的范围之内”
请指教var
  sqlstr1:string;
begin
    //职工号
   if trim(edit_zgh.Text)<>'' then
    sqlstr1:=' zgh='''+trim(edit_zgh.Text)+''''
   else
    sqlstr1:=' 1=1';
   //姓名
   if trim(edit_xm.Text)<>'' then
    sqlstr1:=sqlstr1+' and xm='''+trim(edit_xm.Text)+''''
   else
    sqlstr1:=sqlstr1+' and 1=1';
    //编号
    if trim(edit_bh.Text)<>'' then
     sqlstr1:=sqlstr1+' and bh='''+trim(edit_bh.Text)+''''
    else
     sqlstr1:=sqlstr1+' and 1=1';
  //前往国家
    if trim(edit_qwgj.Text)<>'' then
     sqlstr1:=sqlstr1+' and qwgj='''+trim(edit_qwgj.Text)+''''
    else
     sqlstr1:=sqlstr1+' and 1=1';
    //国家代码
   if trim(edit_gjdm.Text)<>'' then
    sqlstr1:=sqlstr1+' and gjdm='''+trim(edit_gjdm.Text)+''''
   else
    sqlstr1:=sqlstr1+' and 1=1';
    //日期比较
    if checkbox1.Checked=true then
    begin
      sqlstr1:=sqlstr1+' and  cgsj>:datetimepicker1.date';
      sqlstr1:=sqlstr1+' and  cgsj<:datetimepicker2.date';
    end;  ClientDataSet1.Close;
  ClientDataSet1.commandtext:='select zgh,xm,cgsj,bh,qwgj,gjdm,hjsj,cfsj,pwbh,pzr,cgsy,sxry,bz,to_char(cgsj,''yyyy-mm-dd'') cgsj1,to_char(cfsj,''yyyy-mm-dd'') cfsj1,to_char(hjsj,''yyyy-mm-dd'') hjsj1 from jscgb where '+sqlstr1+''; 
  ClientDataSet1.Open;
  groupbox2.Caption:='共有记录'+inttostr(ClientDataSet1.RecordCount)+' 条';
  if not clientdataset1.Eof then
  begin
    n1.Visible:=true;
    n2.Visible:=true;
    n3.Visible:=true;
    n4.Visible:=true;
    n6.Visible:=true;
    n7.Visible:=true;
    Excel1.Visible:=true;
  end;
end;

解决方案 »

  1.   

    sqlstr1:=sqlstr1+' and  cgsj>:datetimepicker1.date'; 这是个什么东西?
    datetimepicker1.date怎么能作为参数呢
      

  2.   

        //日期比较 
        if checkbox1.Checked=true then 
        begin 
          sqlstr1:=sqlstr1+' and  cgsj>:d1'; 
          sqlstr1:=sqlstr1+' and  cgsj <:d2'; 
        end;   ClientDataSet1.Close; 
      ClientDataSet1.commandtext:='select zgh,xm,cgsj,bh,qwgj,gjdm,hjsj,cfsj,pwbh,pzr,cgsy,sxry,bz,to_char(cgsj,''yyyy-mm-dd'') cgsj1,to_char(cfsj,''yyyy-mm-dd'') cfsj1,to_char(hjsj,''yyyy-mm-dd'') hjsj1 from jscgb where '+sqlstr1+''; 
       ClientDataSet1.Params.ParamByName('d1').value := datetimepicker1.date;
       ClientDataSet1.Params.ParamByName('d2').value := datetimepicker2.date;
      

  3.   

    谢谢楼上两位
    我是新手。。不好意思
    按照2楼的那样做之后还是有些问题
    出现错误ora 00932的错误。。是不一致的数据类型,expected date got number
    怎么办?
      

  4.   

    把SQL语句跟踪出来,在数据库上执行一下看看出现什么问题.
      

  5.   

    ok两位解决了
    楼上给的ClientDataSet1.Params.ParamByName('d1').value := datetimepicker1.date; 
            ClientDataSet1.Params.ParamByName('d2').value := datetimepicker2.date;改成ClientDataSet1.Params.ParamByName('d1').asdate := datetimepicker1.date; 
        ClientDataSet1.Params.ParamByName('d2').asdate := datetimepicker2.date;
    就ok了