Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am getting the error "Conversion from type 'DBNull' to type 'String' is not valid."

see the code
------------
Currency.SelectedValue = IIf(IsDBNull(Trim(Rdr("CurrencyCode"))), "", Trim(Rdr("CurrencyCode")))


what is the problem..?
Posted
Updated 26-Jul-11 22:43pm
v2

Don't use IIF, use If conditions.
IIF evaluates whole expression without considering condition.
 
Share this answer
 
The Trim(). Try this:
Currency.SelectedValue = IIf(IsDBNull(Rdr("CurrencyCode")), "", Trim(Rdr("CurrencyCode")))


[Edit]
Prerak's right, I forgot that it is VB you are using. Still, the Trim() in the conditional should be removed.
[/edit]
[edit2:Sorry I got your name wrong]
 
Share this answer
 
v3
You can also check value with DBNull.Value

If Rdr("CurrencyCode")=DBNull.Value
End If
Regards,
Nitin Verma
 
Share this answer
 
Try this.
Currency.SelectedValue = IIf(IsDBNull(Rdr("CurrencyCode")) = True, "", Trim(Rdr("CurrencyCode")))
 
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