473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting error with IsDBNull and not sure why

I have the following line in my code

paid.MonthsPaid = IIf(IsDBNull(Ro w("MonthsPaid") ),
Integer.MinValu e, Convert.ToInt16 (Row("MonthsPai d")))

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 3283
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("Month sPaid")
End if
///

I hope this helps,

Cor
Jul 21 '05 #2
BillG <Bi***@discussi ons.microsoft.c om> wrote:
I have the following line in my code

paid.MonthsPaid = IIf(IsDBNull(Ro w("MonthsPaid") ),
Integer.MinValu e, Convert.ToInt16 (Row("MonthsPai d")))

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.co m>
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.co m>
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
1689
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 actually have) MySQL = "Insert into Activity (ActivityName) Values ('" + GetString(2) + "')"; Here is the JIT Error..."Data is Null. This method or property cannot be called on Null Values"
5
1373
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
1349
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 = dsSystemInformation.Tables("SystemInfo").Columns("System").ToString ddlSystem.DataBind() 'populate text boxes with mathing values
2
1615
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 bounce the web server. The error can be seen below. I have looked at the stack trace and determined where the error is occuring but when I look at my code, where it says that I have an unhandled exception, I have error handling to handle it. ...
2
1167
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 type 'DBNull' to type 'String' is not valid." This error is caused by the null values. How can I avoid this error? Dim i As Integer = QueueReader.GetOrdinal("CustomerId") If QueueReader.Read() And Not QueueReader.IsDBNull(i) Then
3
3591
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 labels without checking first. Is there a better method to write this than using a bunch of "If" statements? Could it be a function? if so, how would I write it? 'Read the single record While drLeadFeedback.Read() If Not...
3
9929
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 (SP1) installed. The error is: System.Runtime.InteropServices.COMException(0x800A03EC): Exception from HRESULT: 0x800A03EC. at Microsoft.Office.Interop.Excel._Worksheet.Paste(Object Destination, Object Link) at...
4
936
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 cast from DBNull to other types. What am I doing wrong?
2
4921
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 control: <asp:HyperLink id="lnkRefine" runat="server" >Refine Search</asp:HyperLink> In the code behind I am trying to set the NavigateURL depending upon a condition. I include the entire Sub since it may reveal what I am doing
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10578
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.