BillG <Bi***@discussions.microsoft.com> wrote:
I have the following line in my code
paid.MonthsPaid = IIf(IsDBNull(Row("MonthsPaid")),
Integer.MinValue, Convert.ToInt16(Row("MonthsPaid")))
and I get the error message
Object cannot be cast from DBNull to other types.
What am I doing wrong?
From the docs for Iif:
<quote>
Note The expressions in the argument list can include function calls.
As part of preparing the argument list for the call to IIf, the Visual
Basic compiler calls every function in every expression. This means
that you cannot rely on a particular function not being called if the
other argument is selected by Expression.
</quote>
To my mind, that makes it a lot less useful than the normal ternary
operator of languages such as C/C++, Java and C#.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too