select *
from table1
where begintime>=#2004-01-01 15:00:00#
and endtime<#2004-05-01 15:00:00#上面的语句在Sql expoloer中可以运行而在DELPHI的SQL中确要报错error: '00:00#' unknow type
from table1
where begintime>=#2004-01-01 15:00:00#
and endtime<#2004-05-01 15:00:00#上面的语句在Sql expoloer中可以运行而在DELPHI的SQL中确要报错error: '00:00#' unknow type
begin
close;sql.clear;//..........
sql.add('select * from table1 where begintime>='+quotedstr('2004-01-01 15:00:00')+'and endtime<'+quotedstr('2004-05-01 15:00:00'));
open;end;
begin
ParamCheck := false;
Close;
SQL.Clear
SQL.Text = 'select * from table1 where begintime>=#2004-01-01 15:00:00# and endtime<#2004-05-01 15:00:00#';
Open;
end;
ADOQuery1.ParamCheck := False;
//begintime>=#2004-01-01 15:00:00#//一句中就有了一个参数,其名字都是“00:00#”,由于这一名称不符合pascal语言的名称规范,adodataset在将其加入paramaters属性合中报错。
解决这一问题目前只能采取变通方式,就是在对sql语句赋值时,阻止参数自动解析,方法如下:
1、设置dataset.ParamCheck:=false;
2、设置Dataset.sql.addstring('select * from table1 where ((begintime>=#2004-01-01 15:00:00#) and (endtime<#2004-05-01 15:00:00#'))
3、dataset.open;
另外,对于sql语句的where子名,建议多用括号进分隔,这样可以在不同的sql引擎上得到最适当的结果。
如果想将sql语句直接写到dataset的sql属性中,则可采取三个步骤:
1、在IDE中写入sql语句
2、设置paramCheck=false;
3、清除parameters列表中出现的所有参数名称
from table1
where begintime>='2004-01-01 15:00:00'
and endtime<'2004-05-01 15:00:00'
楼主原代码应稍微改为:
select *
from table1
where begintime>=#2004-01-01 15::00::00#
and endtime<#2004-05-01 15::00::00#看见没有??快把分拿来!100分哟,好多好多。。:)
你还需执行:
Parameters.Clear;