兄弟做毕业设计~~马上要交了,求各位大哥帮忙,十分感谢,不能数据库里的日期用的是常规日期,就是yyyy-m-d hh:mm:ss的那种 数据源microsoft jet 4.0
procedure TfrmQuery.BitBtn1Click(Sender: TObject);
var
lowTime,highTime:string;
lowPeriod,highPeriod:string;
s:string;
begin
{处理"查询时间"}
d1.Date;
lowTime:=formatDateTime(YYYY-m-d,d1.date);
lowTime:=lowTime+ 00:00:00;
highTime:=formatDateTime(YYYY-m-d,d2.Date);
highTime:=highTime+ 23:59:59;
{处理"通话时长"}
if edit1.Text<> then
lowPeriod:=edit1.Text+:
else
lowPeriod:=00:;
if edit2.Text<> then
lowPeriod:=lowPeriod+edit2.Text+:
else
lowPeriod:=lowPeriod+00:;
lowPeriod:=lowPeriod+00;
if edit3.Text<> then
highPeriod:=edit3.Text+:
else
highPeriod:=23:;
if edit4.Text<> then
highPeriod:=highPeriod+edit4.Text+:
else
highPeriod:=highPeriod+59:;
highPeriod:=highPeriod+59;
{生成查询语句}
s:=select * from detail ;
s:=s+where 开始时间>=+lowTime+ +
and 开始时间<=+highTime+ +
and 通话时长>=+lowPeriod+ +
and 通话时长<=+highPeriod+ ;
if no.Text<> then
s:=s+and 分机号=+no.Text+;
{执行查询}
showMessage(s);
with query1 do
begin
close;
sql.Clear;
sql.Add(s);
try
open;
except
execsql;
end;
end;
end;
project MDIApp.exe raised exception class EOleException with message标准表达式中数据类型不匹配
with ADOQuery1 do
try
Close;
sql.text:= select * from detail where 开始时间>=:P1 ;
SQL.Add( and 开始时间<=:p2 and 通话时长>=:p3 and 通话时长<=:p4 )
parameters.ParamValues[p1]:=lowTime;
parameters.ParamValues[p2]:=highTime;
parameters.ParamValues[p3]:=lowPeriod;
parameters.ParamValues[p4]:=highPeriod;
if no.Text<> then
begin
Sql.add( and 分机号=:p5 );
parameters.ParamValues[p5]:=no.Text;
end;
except
on E:Exception do ShowMessage(数据库查询出错!+#13+E.message);
end;
可以简洁一些
access数据库的日期应该用#号,而不是单引号
例如(birthday 是 t_user表的一个日期类型数据):
SELECT * FROM t_user where birthday > #1977-01-01# 是正确的
而
SELECT * FROM t_user where birthday > 1977-01-01则会出现你所说的错误