Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 4th, 2006, 02:16 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: San Francisco, CA, USA.
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old August 30th, 2007, 07:37 AM
Authorized User
 
Join Date: Aug 2007
Location: mumbai, maharashtra, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about value class type saadli BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 4 December 3rd, 2008 10:15 PM
Nullable Datetime shivamnshah BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 April 26th, 2007 12:46 PM
Research Type Question nadee Oracle 0 March 18th, 2007 11:12 PM
Question about Nullable Types Aaron Edwards ASP.NET 2.0 Basics 5 December 10th, 2006 11:57 PM
Data Type Question dparsons ASP.NET 1.0 and 1.1 Professional 0 March 23rd, 2006 06:07 PM





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