473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting error with IsDBNull and not sure why

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?

Jul 21 '05 #1
4 3255
BillG,

Avoid using the IIF. I have seen more that there is a kind of special logic
in it.
As well do not use the Short(int16) when it is not really needed, the
Integer(Int32) is in VBNet the default.

Why not just use
\\\
If Row("MonthsPaid") Is DBNull.value then
paid.MonthsPaid = 0
Else
paid.MonthsPaid = Cint(Row("MonthsPaid")
End if
///

I hope this helps,

Cor
Jul 21 '05 #2
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
Jul 21 '05 #3
Jon,
To my mind, that makes it a lot less useful than the normal ternary
operator of languages such as C/C++, Java and C#.


And JavaScript where it is in my opinon often used.

You sentence is in my opinion "true", maybe can you add that to your page
and than directly change that awful "With" part and look at that IDE part as
you promished.

(As an advantage from C# of course)

:-)

Cor
Jul 21 '05 #4
Cor Ligthert <no************@planet.nl> wrote:
To my mind, that makes it a lot less useful than the normal ternary
operator of languages such as C/C++, Java and C#.
And JavaScript where it is in my opinon often used.

You sentence is in my opinion "true", maybe can you add that to your page
and than directly change that awful "With" part and look at that IDE part as
you promished.


I still don't think the With part is awful (clearly many VB.NET fans
feel it is an advantage as they ask why it isn't in C#, and clearly
many C# fans feel it's not an advantage as they say they're glad it
isn't in there), but I'll remove it seeing as it seems to rub you up
the wrong way so much. I'll try to find some time to test the large
VB.NET solution business. Unfortunately my time is *very* limited at
the moment...
(As an advantage from C# of course)


Thing is, it's not that much of an advantage - not significant by any
stretch of the imagination, as just using a multi-line select fixes the
problem, as has already been mentioned.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
Hello all, I have an SQL Insert statement I'm trying to run via ExecuteNonQuery. It works fine so long as there are no nulls values. Here is the statement...(its a shortened version of what i...
5
by: luna | last post by:
how to i use isdbnull on two tables ? im pulling out the data with a stored procedure like this :- CREATE PROCEDURE search @search varchar(8) AS
7
by: James D. Marshall | last post by:
This is working fine, this is from the page_load subroutine, 'bind System column of SystemInfo table ddlSystem.DataSource = dsSystemInformation.Tables("SystemInfo") ddlSystem.DataTextField =...
2
by: James Wallace | last post by:
I hope that someone can help me out there with this problem. I get an itermittant problem with our web page that occurs about once every 10 to 15 days where the only way to fix the problem is to...
2
by: Justin | last post by:
Below is the code I am using to display a list of values from a table row the problem is some of these columns may be null. Currently when I execute this code I get the following error: "Cast from...
3
by: Paul D. Fox | last post by:
I have this code snippet below where I'm loading all the labels based upon the retrieved record from the DataReader. Unfortunatley, some of the values are null, so I can't explicitly set the...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
4
by: BillG | last post by:
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...
2
by: John Kotuby | last post by:
Hi guys... I must be going brain dead from working on this project for 80 hours in the last week. I suppose that's part-time for some coders.. anyway... I created a simple Hyperlink in a user...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.