Click here to Skip to main content
15,907,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
<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[]'.
Posted
Updated 10-May-17 19:56pm
v2

1 solution

Here Is The Solution of this problem.
VB
objUser.Password_Hash = If(reader.IsDBNull(reader.GetOrdinal("Password_Hash")),
                           New Byte() {},
                           DirectCast(reader("Password_Hash"), Byte()))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900