gpt4 book ai didi

delphi - 空日期时间值 30/12/1899 或 01/01/1800

转载 作者:行者123 更新时间:2023-12-03 18:05:47 25 4
gpt4 key购买 nike

我有以下...

var
LCnn: TADOConnection;
qryGetData: TADOQuery;
begin
...
//build a connection string to a SQL Server 2008
...
qryGetData.Connection := LCnn;
qryGetData.SQL.Text := 'SELECT * FROM MYTABLE'
...
LDate := qryGetData.FieldByName('Date').AsDateTime; //Date its a datetime field in the table

end;

这工作正常,但是,当“日期”字段在某些 Pc 中为 NULL 时,LDate 为 0 而在另一个中为 -36522。

有什么想法吗???谢谢!

编辑:

奇怪的行为是

function TDateTimeField.GetAsDateTime: TDateTime;
begin
if not GetValue(Result) then Result := 0;
end;

在第一种情况下,GetValue 结果为假,因此 GetAsDateTime 结果为 0,在第二种情况下,GetValue 结果为真,因此返回 -36522 (01/01/1800)

最佳答案

TDateTime 没有空值。这意味着如果数据库有空日期那么你的程序是错误的。您需要给予此类日期特殊待遇。只有在确定该字段不为空后才调用 AsDateTime。如果您遇到空字段,您需要以某种特殊方式处理它,但您不能在 TDateTime 中放置一个明确表示为空的值,因为不存在这样的值。

关于delphi - 空日期时间值 30/12/1899 或 01/01/1800,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20402873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com