Sql.Add('select * from main.db d1,chanpin.db d2 where d1.riqi= :Date');ParamByName('Date').AsDate :=datetimepicker1.date;
试试

解决方案 »

  1.   

    运行时提示“parameter 'date' not found”
      

  2.   

    1,在Query的Parems中增加参数aDate
    2,在Query的SQL属性中加入select * from main.db d1,chanpin.db d2 where d1.riqi= :Date;
    3,程序中写入以下代码即可
      with Query1 do
        Close;
        Params[0].Value := DateTimePicker1.Date;
        Open;
      end;
    当然,也可以所有步骤都用代码完成
      

  3.   

    上面的参数aDate为Date型,Input参数
      

  4.   

    XQfish(龙猪) 的程序没错,关键你自己没在程序里先定义
    DATE变量,这叫动态SQL,在QUERY里面就能定义SQL参数.
    Kylixer(甲克虫) 的程序就是这个道理不过一般都是用字符性的.
    你原来可能是日期格式用缺省的,变成字符串时和PARDOX的时间格式
    不同.可以先用SQL查出PARADOX的日期在插入的时候要求格式是怎么样的?
    再DELPHI有个函数可以把日期照一定的掩码格式转变的吧!
      

  5.   

    //功能:将月份的数值转为英文单词缩写
    function TForm1.MonthToEnglish(iMonth: Integer): string;
    begin
      case iMonth of
       1 : Result:='JAN';
       2 : Result:='FEB';
       3 : Result:='MAR';
       4 : Result:='APR';
       5 : Result:='MAY';
       6 : Result:='JUN';
       7 : Result:='JUL';
       8 : Result:='AUG';
       9 : Result:='SEP';
       10 : Result:='OCT';
       11 : Result:='NOV';
       12 : Result:='DEC';
       else
         Result:='';
      end;end;
    然后按格式"日-月-年"组织日期,如"22-Jan-2002",一定要用双引号,如
    select * from main where rq="22-Jan-2002"
    该语句在SQL Explorer中执行正确
    当然,就我所知也就Paradox中这样用.
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      sDate,sSqlDate,sSql:string;
      iCount:integer;
    begin
      sDate:=FormatDateTime('yyyymmdd',dtp.DateTime);
      sSqlDate:=Copy(sDate,7,2) + '-' + MonthToEnglish(StrToInt(Copy(sDate,5,2))) +
       '-' +  Copy(sDate,1,4);
      sSql:='select * from main where rq<"' + sSqlDate +'"';
      Query1.Close;
      Query1.SQL.Clear;
      Query1.SQL.Add(sSql);
      Query1.Open;
      iCount:=Query1.RecordCount;
      MessageBox(handle,PChar(IntToStr(iCount)),'提示',MB_OK);
    end;