我通过选择时间段查询数据,例如2009-10-01到2009-10-14之间的数据,用下面的代码运行的时候,全是空白的,然后我点刷新,提示我错误“FROM字句语法错误”
代码如下:
procedure TForm1.RzBitBtn5Click(Sender: TObject);
begin
with ADOQuery1 do
begin
Filtered:= False;
adoquery1.SQL.Add('select * from Attendance where [Date]>='''+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit1.Date)+''' and [Date]<='''+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit2.Date)+'''');
Filtered :=True;
end;
end;
代码如下:
procedure TForm1.RzBitBtn5Click(Sender: TObject);
begin
with ADOQuery1 do
begin
Filtered:= False;
adoquery1.SQL.Add('select * from Attendance where [Date]>='''+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit1.Date)+''' and [Date]<='''+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit2.Date)+'''');
Filtered :=True;
end;
end;
'#'+日期+'#'
begin
close;
sql.text := 'select * from attendance where [Date]>=:Date1 and [Date]<=:Date2';
Parameters.parambyname('date1').value := strtodate(FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit1.Date));
Parameters.parambyname('date2').value := strtodate(FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit2.Date));
Open;
end;
错误提示“[Error] Unit1.pas(127): Constant expression expected”
好像是这样
adoquery1.SQL.Add('select * from Attendance where [Date]>=''#' +FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit1.Date)+ '#'' and [Date] <=''#' +FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit2.Date)+ '# ''');用参数方式,省出不少麻烦事
报错[Error] Unit1.pas(127): Missing operator or semicolon
begin
with ADOQuery1 do
begin
Filtered:= False;
adoquery1.SQL.Add('select * from Attendance where [Date]>=''#'+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit1.Date)+ '#'' and [Date]<=''#'+FormatDateTime('yyyy-mm-dd',RzDBDateTimeEdit2.Date)+ '#''');
Filtered :=True;
end;
end;
调试通过之后,运行,选择时间之后,出现的是空白的数据,然后我点击更新按钮就提示我“from子句错误”