DBNull 的评估检查不起作用
<%# Eval("Description") == DBNull.Value ? "empty" : "notempty"%>
即使数据库中该字段中有 null (varchar() 类型,null),也始终显示“notempty” ... 还尝试检查空字符串:
<%# Eval("Description") == "" ? "empty" : "notempty"%>
它总是显示 notempty...这里出了什么问题?
<%# Eval("Description") == DBNull.Value ? "empty" : "notempty"%>
is showing always 'notempty' even there is null in that field in DB (type of varchar(), null)
...
Tried also checking for empty string:
<%# Eval("Description") == "" ? "empty" : "notempty"%>
and it always displays notempty... what's wrong here??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DBNull.Value
和null
之间存在差异。该字段可能返回null
。:
另外,如果字段值类型应该是字符串,您可以尝试执行以下操作
There is a difference between
DBNull.Value
andnull
. It is possible the field is returningnull
.Try
Also if the field value type is supposed to be string you could do something along the lines of..
您是否尝试过使用此方法:
Have you tried using this method:
它实际上并未在此级别存储
DBNull
。您需要查找null
或空字符串,其中string.IsNullOrEmpty
应该足够了,并且可以捕获null
和空的两种状态。It is not actually storing
DBNull
at this level. You need to look fornull
or an empty string whichstring.IsNullOrEmpty
should be enough and will capture both states ofnull
and empty.