首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi+access 按时间查询时,出错了,该怎么处理

2012-02-20 
delphi+access 按时间查询时,出错了请高手指点下,我在access数据库中用如下的语句查询,可以得到结果Select

delphi+access 按时间查询时,出错了
请高手指点下,我在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;

[解决办法]
Strutils
sSQL := sSQL + ' where whenPrepaid >=' +Quotedstr(DateTimeBegin)+' and whenPrepaid <= '+Quotedstr(DateTimeEnd);
if ComboBoxOper.Text<> '' then
begin
sSQL := sSQL + ' and whoPrepaid='+QuotedStr(Combobox1.Text);
end;

[解决办法]

Delphi(Pascal) code
  sSQL := sSQL + ' where whenPrepaid >#=' +DateTimeBegin+'# and whenPrepaid <=# '+DateTimeEnd+'#'; 

热点排行