472,784 Members | 877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 3228
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.