UniqueIdentifier不接受nullvalue [英] UniqueIdentifier not accepting nullvalue

查看:90
本文介绍了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 a struct in .NET - which means it's a value type, and that can't hold null values.
If you have null Guids in your database - which is probably a poor idea - then you need to check the returned value against DBNull.Value when you pull it from the reader, and (probably) assign Guid.Empty to your UserID instead.


这篇关于UniqueIdentifier不接受nullvalue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆