gpt4 book ai didi

c# - 对 DBNull 的评估检查不起作用

转载 作者:太空狗 更新时间:2023-10-29 23:55:42 25 4
gpt4 key购买 nike

<%# Eval("Description") == DBNull.Value ? "empty" : "notempty"%>

始终显示“notempty”,即使数据库中的该字段为空(varchar() 类型,空)...还尝试检查空字符串:

<%# Eval("Description") == "" ? "empty" : "notempty"%>

而且总是显示notempty...这是怎么回事??

最佳答案

DBNull.Valuenull 是有区别的。该字段可能返回 null

尝试

<%# Eval("Description") == null ? "empty" : "notempty"%>

此外,如果字段值类型应该是字符串,您可以按照以下方式做一些事情。

<%# (Eval("Description") as string) ?? "empty" %>

关于c# - 对 DBNull 的评估检查不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5224264/

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