Delphi日期设置为NULL

在某些情况下,需要将日期字段的值置空,这种操作比较麻烦。在操作的时候,可将变量的值(t:TDateTime)设置为0,在操作的过程中进行判断,当t的值为0或-1的时候,时间值为1899年的Delphi日期最小值,如果使用SQL设置日期的空值,可直接用:
update [table] set dt=null where …
如果是字段操作,使用:
FieldByName(‘dt’).AsString:=’’
操作后在库中相应的值显示为NULL。

补充:如果用Tquery的参数,
ParamByName('yourdate').DataType := ftDateTime;
ParamByName('yourdate').Isnull;

DataSet.Fieldbyname('').Clear;
update 表 set 字段=null

1899/12/30对应的TDatetime为0。

posted @ 2013-07-08 08:32  findumars  Views(2358)  Comments(1Edit  收藏  举报