UniqueIdentifier不接受nullvalue [英] UniqueIdentifier not accepting nullvalue
本文介绍了UniqueIdentifier不接受nullvalue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
UserID UniqueIdentifier提交
us.UserID =(Guid)reader [UserID];我怎么检查
null value plz帮帮我
推荐答案
Guid
是.NET中的struct
- 这意味着它是值类型,并且不能保持null
值。
如果你有null Guid
在你的数据库中 - 这可能是一个糟糕的主意 - 那么当你从阅读器中取出时,你需要检查返回值DBNull.Value
,并且(可能)分配Guid.Empty
改为您的UserID。
Guid
is astruct
in .NET - which means it's a value type, and that can't holdnull
values.
If you havenull Guid
s in your database - which is probably a poor idea - then you need to check the returned value againstDBNull.Value
when you pull it from the reader, and (probably) assignGuid.Empty
to your UserID instead.
这篇关于UniqueIdentifier不接受nullvalue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文