读书人

日期比较有关问题 access

发布时间: 2012-03-28 15:40:03 作者: rapoo

日期比较问题 access
procedure TForm2.Button8Click(Sender: TObject);
var
str1,str2:string;

begin
with adoquery2 do
begin
str1:=datetimetostr(DateTimePicker3.datetime);
str2:=datetimetostr(DateTimePicker4.datetime);
if ComboBox4.Text='' then
begin
close;
sql.Clear;
sql.Add('select * from sj where yh='''+yhs+''' and date1>='''+str1+''' and date1<='''+str2+'''') ;


open;
end
else
begin
if ComboBox3.text='' then
begin
close;
sql.Clear;
sql.Add('select * from sj where date1<=:'''+str1+''' and date1>=:'''+str2+''' and zc='''+ComboBox4.text+''' and yh='''+yhs+''' ') ;
open;
end
else
begin
close;
sql.Clear;
sql.Add('select * from sj where date1<=:'''+str1+''' and date1>=:'''+str2+''') and zc='''+ComboBox4.text+''' and ly='''+ComboBox3.text+''' and yh='''+yhs+''' ') ;
open;
end;
end;
end;
end;


[解决办法]
如果 数据库中date1是日期时间类型
sql.Add('select * from sj where date1 BETWEEN DateValue('''+str1+''') and DateValue('''+str2+''') and zc='''+ComboBox4.text+''' and yh= '''+yhs+'''') ;

读书人网 >.NET

热点推荐