with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from cars where "'+combobox1.text+'">a and "'+combobox1.text+'"=b');
parameters.ParamByName('a').Value:=datetimetostr(datetimepicker1.date);
parameters.ParamByName('b').Value:=datetimetostr(datetimepicker2.Date);
open;
end;查询不出数据,没有错误提示。。
begin
close;
sql.Clear;
sql.Add('select * from cars where "'+combobox1.text+'">a and "'+combobox1.text+'"=b');
parameters.ParamByName('a').Value:=datetimetostr(datetimepicker1.date);
parameters.ParamByName('b').Value:=datetimetostr(datetimepicker2.Date);
open;
end;查询不出数据,没有错误提示。。
参数前加":"
'select * from cars where '+combobox1.text+'>:a and '+combobox1.text+'=:b'简化就是... where Field>:a and Field=:b
又大于,又等于,条件矛盾应该是无数据
begin
close;
sql.Clear;
sql.Add('select * from cars where "'+combobox1.text+'">:a and "'+combobox1.text+'"<:b');
parameters.ParamByName('a').Value:=datetimetostr(datetimepicker1.date);
parameters.ParamByName('b').Value:=datetimetostr(datetimepicker2.Date);
open;
end;呵呵,失误,刚才搞错了,这样搞还是没有查询出数据,,
begin
close;
sql.Clear;
sql.Add('select * from cars where '+combobox1.text+'>'':a''
and '+combobox1.text+'='':b''');
parameters.ParamByName('a').Value:=datetimetostr(datetimepicker1.date);
parameters.ParamByName('b').Value:=datetimetostr(datetimepicker2.Date);
open;
end;a b 都是时间参数,那么在替换参数时应该在参数左右两边加引号,而不是在你在ComboBox所表示的列名左右加引号
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(
format('select * from cars where %s > :a and %s = :b', [combobox1.text, combobox1.text]);
);
parameters.ParamByName('a').Value:= QuotedStr(datetimetostr(datetimepicker1.date));
parameters.ParamByName('b').Value:= QuotedStr(datetimetostr(datetimepicker2.Date));
open;end;