delphi datetimepicker

来源:百度知道 编辑:UC知道 时间:2024/05/29 16:41:23
我需要查找数据库里在某个时间段的记录,想用两个datetimepicker选择时间段后点查找随后就能在DBGRID里面显示这个时间段里的内容,如果还添加一个edit增加一个查询的条件我又该怎么做!
请各位大侠帮忙

给你一个实际的例子参考下

procedure TFcwjszc.btnzccxClick(Sender: TObject);
var
mPubMonth1,mPubMonth31:string;
sqlstr,wherestr,orderstr:string;
begin
sqlstr:='';
wherestr:='';
mPubMonth1:=formatdatetime('yyyy-MM-dd',d1.Date);
mPubMonth31:=formatdatetime('yyyy-MM-dd',d2.Date);
case dbtype of
0: //access下查询+
wherestr:=' where riqi between #'+mPubMonth1+'# and #'+mPubMonth31+'# and';
1://sql下查询
wherestr:=' where riqi between '''+mPubMonth1+''' and '''+mPubMonth31+''' and';
end;

if trim(comzclb.text)<>'' then
if trim(comzclb.Text)<>'不限' then
wherestr:=wherestr+' name='''+trim(comzclb.Text)+''' and';
wherestr:=copy(wherestr,1,length(wherestr)-4);

{ comzcpx.Items.Add('编码