在VB中的IIF条件下,check byte()如何为空 [英] How do check byte() is null in IIF condition in VB

查看:89
本文介绍了在VB中的IIF条件下,check byte()如何为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在db中有一个哈希格式的列值,列数据类型是varbinary(8000)。我将它转换为字节数组。 

问题是这个列值有空值的时候了,现在在我的代码中我想检查列值是否具有空值然后返回字节数组的默认值,否则使用以下代码返回列值





我的尝试:



< pre lang =vb>< pre> objUser.Password_Hash = IIf(reader( Password_Hash Nothing ,{},reader( Password_Hash))



 System.InvalidCastException:无法将System.Byte类型的对象强制转换为System。字节[]'。

解决方案

这是解决这个问题的方法。

 objUser.Password_Hash =  If (reader.IsDBNull(reader.GetOrdinal(  Password_Hash)),
字节( ){},
DirectCast (reader( Password_Hash),字节()))


I have a column value in Hash format in db and column datatype is varbinary(8000).I convert it into byte array.

Problem is some time this column value has null value,now in my code I want to check if column value has null value then return default value of byte array,otherwise return column value using following code



What I have tried:

<pre> objUser.Password_Hash = IIf(reader("Password_Hash") Is Nothing, {}, reader("Password_Hash"))


System.InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.Byte[]'.

解决方案

Here Is The Solution of this problem.

objUser.Password_Hash = If(reader.IsDBNull(reader.GetOrdinal("Password_Hash")),
                           New Byte() {},
                           DirectCast(reader("Password_Hash"), Byte()))


这篇关于在VB中的IIF条件下,check byte()如何为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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