1

String.IsNullOrWhiteSpace(valuefromDB) throws error if valuefromDB is dbnull.value

Is that correct??

I thought of this function will also handles the dbnull.value

0

3 Answers 3

3

DBNull.Value does not equal null.

Try something like:

If Not DbNull.Value.Equals(valuefromDB)...
Sign up to request clarification or add additional context in comments.

Comments

1

If you had Option Strict On your code would never have compiled, because the IsNullOrWhiteSpace method on string accepts a string type, DBNull isn't a string type (it's DBNull), and at a guess your valuefromDB variable is of type Object.

The IsNull in the name IsNullOrWhiteSpace is actually referring to the CLRs null which in VB is Nothing, not DBNull

You can either check for both DBNull and IsNullOrWhiteSpace or as pointed out by Emaad Ali, use the VB function IsNothing.

Hope this helps

Comments

0

Yes is correct..

From msdn:

Indicates whether a specified string is Nothing, empty, or consists only of white-space characters.

Nothing is not null, so your string can be nothing or empty, but a dbnull is another different value for it :).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.