str1:=str1+' and between(rq,{'+rq1+'},{'+rq2+'})'; 上面这句应修改为: str1:=str1+' and (rq between :rq1 and :rq2))';
to nne998(上上下下左右左右BABA) and wylove(阿刚) 我按楼上几位兄弟做了,但是不对
不要用ADOQuery.open 用ADOQuery.ExecSQL
form1.ADOConnection1.close; rq1:='2001-08-01'; rq2:='2001-08-31'; form1.ADOQuery1.Close; form1.ADOConnection1.Open; form1.adoquery1.sql.clear; form1.adoquery1.sql.add('select daa01.cyjh,rq,ccynd,ccynd1'); form1.adoquery1.sql.add(' from daa01,dba01'); form1.adoquery1.sql.add(' where daa01.jh=dba01.jh'); form1.adoquery1.sql.add(' and (dba01.ccynd<>0 or dba01.ccynd1<>0)'); form1.adoquery1.sql.add(' and rq between :rq1 and :rq2'); form1.ADOQuery1.Parameters.ParamByName('rq1').value:=strtodate('2001-08-01'); form1.adoquery1.parameters.parambyname('rq2').value:=strtodate('2001-08-31'); form1.label1.Caption:=form1.ADOQuery1.SQL.text; form1.ADOQuery1.Prepared; form1.ADOQuery1.Open;你要确认是不是SQL语句的问题,你要把错误提示贴出来。
--------------------------- Debugger Exception Notification --------------------------- Project Project1.exe raised exception class EOleException with message '数据提供程序或其他服务返回 E_FAIL 状态。'. Process stopped. Use Step or Run to continue. --------------------------- OK Help --------------------------- 出错信息如上
这是按你写的代码出的提示出错信息。(为日期型参数时) 重贴一遍关键代码: procedure TForm1.Button1Click(Sender: TObject); var str1:string; rq1,rq2:Tdatetime; begin form1.ADOConnection1.close; form1.ADOQuery1.Close; form1.ADOConnection1.Open; form1.adoquery1.sql.clear; form1.adoquery1.sql.add('select daa01.cyjh,rq,ccynd,ccynd1'); form1.adoquery1.sql.add(' from daa01,dba01'); form1.adoquery1.sql.add(' where daa01.jh=dba01.jh'); form1.adoquery1.sql.add(' and (dba01.ccynd<>0 or dba01.ccynd1<>0)'); form1.adoquery1.sql.add(' and rq between :rq1 and :rq2'); form1.ADOQuery1.Parameters.ParamByName('rq1').value:=strtodate('2001-08-01'); form1.adoquery1.parameters.parambyname('rq2').value:=strtodate('2001-08-31'); // form1.label1.Caption:=form1.ADOQuery1.SQL.text; form1.ADOQuery1.Prepared; form1.ADOQuery1.Open; end;
在delphi查询的字符串中使用的函数是不是只要vfp支持就行,
不用管delphi是否支持
上面这句应修改为:
str1:=str1+' and (rq between :rq1 and :rq2))';
我按楼上几位兄弟做了,但是不对
用ADOQuery.ExecSQL
rq1:='2001-08-01';
rq2:='2001-08-31';
form1.ADOQuery1.Close;
form1.ADOConnection1.Open;
form1.adoquery1.sql.clear;
form1.adoquery1.sql.add('select daa01.cyjh,rq,ccynd,ccynd1');
form1.adoquery1.sql.add(' from daa01,dba01');
form1.adoquery1.sql.add(' where daa01.jh=dba01.jh');
form1.adoquery1.sql.add(' and (dba01.ccynd<>0 or dba01.ccynd1<>0)');
form1.adoquery1.sql.add(' and rq between :rq1 and :rq2');
form1.ADOQuery1.Parameters.ParamByName('rq1').value:=strtodate('2001-08-01');
form1.adoquery1.parameters.parambyname('rq2').value:=strtodate('2001-08-31');
form1.label1.Caption:=form1.ADOQuery1.SQL.text;
form1.ADOQuery1.Prepared;
form1.ADOQuery1.Open;你要确认是不是SQL语句的问题,你要把错误提示贴出来。
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOleException with message '数据提供程序或其他服务返回 E_FAIL 状态。'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
出错信息如上
重贴一遍关键代码:
procedure TForm1.Button1Click(Sender: TObject);
var
str1:string;
rq1,rq2:Tdatetime;
begin
form1.ADOConnection1.close;
form1.ADOQuery1.Close;
form1.ADOConnection1.Open;
form1.adoquery1.sql.clear;
form1.adoquery1.sql.add('select daa01.cyjh,rq,ccynd,ccynd1');
form1.adoquery1.sql.add(' from daa01,dba01');
form1.adoquery1.sql.add(' where daa01.jh=dba01.jh');
form1.adoquery1.sql.add(' and (dba01.ccynd<>0 or dba01.ccynd1<>0)');
form1.adoquery1.sql.add(' and rq between :rq1 and :rq2');
form1.ADOQuery1.Parameters.ParamByName('rq1').value:=strtodate('2001-08-01');
form1.adoquery1.parameters.parambyname('rq2').value:=strtodate('2001-08-31');
// form1.label1.Caption:=form1.ADOQuery1.SQL.text;
form1.ADOQuery1.Prepared;
form1.ADOQuery1.Open;
end;
第二遍时,sql语句等于两次得相加了,所以出错了,
运行一遍后,要把变量变成空
可以了吗?