p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Nullable Type Question (http://p2p.wrox.com/showthread.php?t=51067)

Aaron Edwards December 4th, 2006 02:16 AM

Nullable Type Question
 
I have a variable defined as Nullable (Of Int32). But I can't seem to assign it a value of DBNull. Seems it can only take VBNull. How the heck am I supposed to use it with a database then? The following code breaks every time a null value comes out of the database:

dim myNullableInt as Nullable (of Int32)
myNullableInt = myDataReader("myPossiblyNullField")

HELP!

Aaron


shakti_2505270 August 30th, 2007 07:37 AM

hi Aaron
this is Shakti, i work as Software Programmer.

Your query can be easily solved.
You dont have to define a nullable variable.
Just define a variable of ur required type, in this case integer.

the code goes like this (the code has been written in C#, u can transform it to VB)

int i;
if(myDataReader("myPossiblyNullField")==DBNULL.Val ue)
{
i=0;// whatever the value u want to pass for null database values.
}
else
{
i=myDataReader("myPossiblyNullField");
}


hope u find it helpful.
reply ur comments.


All times are GMT -4. The time now is 02:58 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.