在某些情况下,需要将日期字段的值置空,这种操作比较麻烦。在操作的时候,可将变量的值(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。

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-06-05
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案