大家帮忙看看这段代码,是日期这里的参数错了,但不知怎样改才对。
procedure TForm1.Button1Click(Sender: TObject);
var
querystr:string;
begin
querystr:='select * from patient where 1>0';
if checklistbox1.Checked[0] then
querystr:=querystr+'and 检查号 like '+quotedstr('%'+edit1.Text+'%')+'';
if checklistbox1.Checked[1] then
querystr:=querystr+'and 姓名 like '+quotedstr('%'+edit2.Text+'%')+'';
if checklistbox1.Checked[2] then
querystr:=querystr+'and 科别 like '+quotedstr('%'+combobox1.Text+'%')+'';
if checklistbox1.Checked[3] then
querystr:=querystr+'and 检查部位 like '+quotedstr('%'+combobox2.Text+'%')+'';
if checklistbox1.Checked[4] then
querystr:=querystr+'and 报告医师 like '+quotedstr('%'+combobox3.Text+'%')+'';
if checklistbox1.Checked[5] then
begin
querystr:=querystr+'and 报告时间 between :qm and :hm'';
parameters.ParamByName('qm').Value :=formatdatetime('yyyy-mm-dd',datetimepicker1.Date );
parameters.ParamByName('hm').Value :=formatdatetime('yyyy-mm-dd',datetimepicker2.Date );
end
with adoquery1 do
begin
close;
sql.clear;
sql.add(querystr);
open;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
querystr:string;
begin
querystr:='select * from patient where 1>0';
if checklistbox1.Checked[0] then
querystr:=querystr+'and 检查号 like '+quotedstr('%'+edit1.Text+'%')+'';
if checklistbox1.Checked[1] then
querystr:=querystr+'and 姓名 like '+quotedstr('%'+edit2.Text+'%')+'';
if checklistbox1.Checked[2] then
querystr:=querystr+'and 科别 like '+quotedstr('%'+combobox1.Text+'%')+'';
if checklistbox1.Checked[3] then
querystr:=querystr+'and 检查部位 like '+quotedstr('%'+combobox2.Text+'%')+'';
if checklistbox1.Checked[4] then
querystr:=querystr+'and 报告医师 like '+quotedstr('%'+combobox3.Text+'%')+'';
if checklistbox1.Checked[5] then
begin
querystr:=querystr+'and 报告时间 between :qm and :hm'';
parameters.ParamByName('qm').Value :=formatdatetime('yyyy-mm-dd',datetimepicker1.Date );
parameters.ParamByName('hm').Value :=formatdatetime('yyyy-mm-dd',datetimepicker2.Date );
end
with adoquery1 do
begin
close;
sql.clear;
sql.add(querystr);
open;
end;
end;
var
r1:string;
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from aa where pid=:r1');
parameters.ParamByname('r1').value:='1';
showmessage(sql.Text);
open;
end;
如果不考虑SQL注入,倒是建议你直接把 formatdatetime('yyyy-mm-dd',datetimepicker1.Date ) 直接 代入。