代码是这样的: var me1,me2,me3:tdatetime; begin me1:=strtodatetime(maskedit1.text); me2:=strtodatetime(maskedit2.text); me3:=strtodatetime(maskedit3.text); if radiobutton1.Checked then begin with form2.ADOQuery1 do begin close; sql.clear; sql.Add('select * from kucun where in_time=me1'); open; dbgrid1.DataSource :=form2.DataSource3; form2.ADOQuery1.Active :=true; end; end end;
建议你将格式定义为:!9999/99/00;1;_sql.Add('select * from kucun where in_time=me1');这个错误,注意你的in_time=me1,在这里不会将值赋给in_time的,类型不匹配。 你要明白,你没有将变量me1的值传入,相当于你在sql中使用这个语句查询: select * from kucun where in_time=me1,这里的me1当然无法获取。 你将日期转换代入sql串中,就可以了
sql.add('select * from kucun where in_time=''strtodatetime(maskedit1.text)''') 是这样吗?会出现从'字符串转换为datetime时发生语法错误'
我sql表里的in_time是datetime格式的
sql.add('select * from kucun where in_time=''' + strtodatetime(maskedit1.text) + ''''); 在delphi中,如果想引用一个'号必须使用连续两个。
StrToDate(maskedit1.text);
except
ShowMessage('错误的时间格式');
end;
var me1,me2,me3:tdatetime;
begin
me1:=strtodatetime(maskedit1.text);
me2:=strtodatetime(maskedit2.text);
me3:=strtodatetime(maskedit3.text);
if radiobutton1.Checked then
begin
with form2.ADOQuery1 do
begin
close;
sql.clear;
sql.Add('select * from kucun where in_time=me1');
open;
dbgrid1.DataSource :=form2.DataSource3;
form2.ADOQuery1.Active :=true;
end;
end
end;
你要明白,你没有将变量me1的值传入,相当于你在sql中使用这个语句查询:
select * from kucun where in_time=me1,这里的me1当然无法获取。
你将日期转换代入sql串中,就可以了
是这样吗?会出现从'字符串转换为datetime时发生语法错误'
在delphi中,如果想引用一个'号必须使用连续两个。