delphi+access 按时间查询时,出错了

whilework 2010-04-14 10:44:34
请高手指点下,我在access数据库中用如下的语句查询,可以得到结果
Select *
from tOldCard
where whenPrepaid>=#2010-04-01# And whenPrepaid<=#2010-04-30 23:59:59# And whoPrepaid='admin';

可是在delphi中代码也这样写就报错。
'不正常地定义参数对象。提供了不一致或不完整的信息。'

delphi代码是:
procedure TFrmMain.BBtnSelectClick(Sender: TObject);
var
DateTimeBegin,DateTimeEnd : String;
strOper : String;
sSQL : String;
i : integer;
begin
DateTimeBegin := DateToStr(DateTimePickerBegin.Date)+' 00:00:00';
DateTimeEnd := DateToStr(DateTimePickerEnd.Date) + ' 23:59:59';
strOper := ComboBoxOper.Text;
i := CompareDateTime(DateTimePickerBegin.Date,DateTimePickerEnd.Date);
if i > 0 then
begin
Application.MessageBox('开始时间不能晚于结束时间,请重新选择开始时间!',PChar(Application.Title),mb_IconError);
DateTimePickerBegin.SetFocus;
end;
sSQL := 'select * from tOldCard ';
sSQL := sSQL + ' where whenPrepaid >= '''+DateTimeBegin+''' and whenPrepaid <= '''+DateTimeEnd+''' ';
if ComboBoxOper.Text<> '' then
begin
sSQL := sSQL + ' and whoPrepaid= '''+ ComboBoxOper.Text +''' ';
end;
SelectAllPrepaidCard(ADOQuery2,DBGrid2,sSQL);//SelectAllPrepaidCard自定义的一个函数
end;
...全文
93 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
PinkPacino 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 bdmh 的回复:]
Delphi(Pascal) code

sSQL := sSQL + ' where whenPrepaid >#=' +DateTimeBegin+'# and whenPrepaid <=# '+DateTimeEnd+'#';
[/Quote]

whenPrepaid >= #' +DateTimeBegin+'#
whilework 2010-05-02
  • 打赏
  • 举报
回复
自己后来无意中解决了,SQL语句没有错的,好象Access不支持对对具体的时间查询,
比如只能查询2010-05-02, 而不能这样写2010-05-02 09:30:30。
bdmh 2010-04-14
  • 打赏
  • 举报
回复

sSQL := sSQL + ' where whenPrepaid >#=' +DateTimeBegin+'# and whenPrepaid <=# '+DateTimeEnd+'#';
风之谷 2010-04-14
  • 打赏
  • 举报
回复
Strutils
sSQL := sSQL + ' where whenPrepaid >=' +Quotedstr(DateTimeBegin)+' and whenPrepaid <= '+Quotedstr(DateTimeEnd);
if ComboBoxOper.Text<> '' then
begin
sSQL := sSQL + ' and whoPrepaid='+QuotedStr(Combobox1.Text);
end;

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧