473,385 Members | 1,907 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,385 software developers and data experts.

Nullable types and datareader...

Hi all,

Nullable types were announced as new handy stuff in .NET 2.0
But it seems like the datareader doesn't support nullable types.
You have still to check for "IsDbNull".
So, are Nullable Types useful at this moment? Do you get any benefit using
them (at this moment)?
Is Microsoft going to change this?

Best regards,
Mobile Boy
Dec 12 '06 #1
3 2237
"MobileBoy36" <Mo*********@gmail.comwrote in
news:45***********************@news.skynet.be:
Nullable types were announced as new handy stuff in .NET 2.0
But it seems like the datareader doesn't support nullable types.
You have still to check for "IsDbNull".
So, are Nullable Types useful at this moment? Do you get any benefit
using them (at this moment)?
Is Microsoft going to change this?
I don't think DBNull and Null are the same thing - that's why Nullable
types are not directly converted.

Take a look at LLBLGen Pro - it's a database framework from .NET. It has
support for Nullable types and the like... and MORE :)
Dec 12 '06 #2
Here's an example of using a nullable type. They are
good to use when you need to know if a number is 0 or Null,
because those are two different things, especially if you
are doing numerical calculations.

Dim IntegerData As Nullable(Of Integer)

If IntegerData.HasValue Then
Console.WriteLine("IntegerData = " & IntegerData.ToString)
Else
Console.WriteLine("IntegerData = Null.")
End If

If you read data from a database, you have to check for DBNull
and act accordingly.

IntegerData = Nothing
If NOT IsDBNull(myRow.ProductCode) Then
IntegerData = myRow.ProductCode
End If

Another syntax for this is:
If myRow.ProductCode IsNot DbNull.Value Then
...

Robin S.
------------------------

"MobileBoy36" <Mo*********@gmail.comwrote in message
news:45***********************@news.skynet.be...
Hi all,

Nullable types were announced as new handy stuff in .NET 2.0
But it seems like the datareader doesn't support nullable types.
You have still to check for "IsDbNull".
So, are Nullable Types useful at this moment? Do you get any benefit
using them (at this moment)?
Is Microsoft going to change this?

Best regards,
Mobile Boy


Dec 12 '06 #3
Mobile Boy,
In addition to the other comments.

I find nullable types to be very useful on my domain (business) objects.

My data mappers (data objects) use DataReader.IsDBNull to decide if they
need to return Nothing or a value for the nullable types on the domain
objects.
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"MobileBoy36" <Mo*********@gmail.comwrote in message
news:45***********************@news.skynet.be...
Hi all,

Nullable types were announced as new handy stuff in .NET 2.0
But it seems like the datareader doesn't support nullable types.
You have still to check for "IsDbNull".
So, are Nullable Types useful at this moment? Do you get any benefit using
them (at this moment)?
Is Microsoft going to change this?

Best regards,
Mobile Boy

Dec 14 '06 #4

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

Similar topics

10
by: John Wood | last post by:
I was just looking at an article about using nullable value types. (value types that can effectively have no value and not be set). The syntax is to append a question-mark to the value type in...
12
by: Steven Livingstone | last post by:
I've just blogged some stuff on Nullable types in net 2.0. http://stevenr2.blogspot.com/2006/01/nullable-types-and-null-coalescing.html Question however as to why you can't simply get an implcit...
6
by: Steven Livingstone | last post by:
Bit of advice here folks. I am creating a default constructor that just initializes a new instance of my object and a secon constructor that takes an ID and loads an object with data from the...
8
by: shawnk | last post by:
Given several nullable boolean flags; bool? l_flg_01 = true; bool? l_flg_02 = false; bool? l_flg_03 = true; bool? l_result_flg = null; I would have liked...
0
by: Larry Lard | last post by:
There seems to be something a bit lacking in the way the dataset designer thing deals (or rather doesn't) with nullable fields in VS2005. Maybe it's cos I'm using VB2005 Express (which is variously...
1
by: Joe Bloggs | last post by:
Hi, Can someone please kindly show me how to determine if a type (read value type) is Nullable. MSDN has this KB: How to: Identify a Nullable Type (C# Programming Guide)...
8
by: Sam Kong | last post by:
Hello, I want to define a generic class which should accept only nullable types or reference types. What's the best way to costrain it? --------- class MyClass<T>{ ...
3
by: Mike P | last post by:
What are nullable types used for? The only use I can think of is where I have a method like this where some values being passed to it may be null : public int AddUser(int? UserRegion, string...
6
by: Tony Johansson | last post by:
Hello! I'm reading in a book called Visual C# 2005. In the chapter about Generics there ia a section about Nullable types. Here is the text that isn't complete true I think. It says: "You...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.