473,396 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,396 software developers and data experts.

Dealing with Database Null

I have my object model thing going with some classes that contain properties
that are saved into a database. Some of these properties are *numeric*
properties that can be left Null in the database table.

My problem is that there does not seem to be a way to assign a Null value to
your typical numeric value type variable.

Other than using the sql variables types (which cant' be serialized), can
anyone share some practical solutions on how to go around this limitation?
In other words, how do you guys deal with numeric properties that can be
Null.

Thank you.
Nov 16 '05 #1
5 7809
Hi,

try System.DbNull.Value.

Regards
Joyjit

"Rene" <no****@nospam.nospam> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
I have my object model thing going with some classes that contain properties that are saved into a database. Some of these properties are *numeric*
properties that can be left Null in the database table.

My problem is that there does not seem to be a way to assign a Null value to your typical numeric value type variable.

Other than using the sql variables types (which cant' be serialized), can
anyone share some practical solutions on how to go around this limitation?
In other words, how do you guys deal with numeric properties that can be
Null.

Thank you.

Nov 16 '05 #2
SP
"Rene" <no****@nospam.nospam> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
I have my object model thing going with some classes that contain
properties
that are saved into a database. Some of these properties are *numeric*
properties that can be left Null in the database table.

My problem is that there does not seem to be a way to assign a Null value
to
your typical numeric value type variable.

Other than using the sql variables types (which cant' be serialized), can
anyone share some practical solutions on how to go around this limitation?
In other words, how do you guys deal with numeric properties that can be
Null.


I implement IsMyPropertyNameNull and set this when I am reading from the
datareader. I use a static null checker function that I pass the reader
value and the IsNull property to it. This avoids trying to cast null as a
numeric value and also sets the IsNull to true.

In the setter for the numeric property I set isNull to false.

I do the opposite when writing back to the database. If IsNull is true then
i use DbNull.Value as the parameter value.

HTH

SP

Nov 16 '05 #3
Hi Rene,

This has been discussed here several times, so you can check the archives
for more info.

basically you have two options:
1- Use a wrapper type

2- Use a special value of the type as a null indicator, for exampe I use
DateTime.MinValue to indicate a datetime with no value set in one
application, of course I do so cause that value has no meaning on the
application, if not I cannot use this approach.
Also note that in .NET 2.0 this will change.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Rene" <no****@nospam.nospam> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
I have my object model thing going with some classes that contain properties that are saved into a database. Some of these properties are *numeric*
properties that can be left Null in the database table.

My problem is that there does not seem to be a way to assign a Null value to your typical numeric value type variable.

Other than using the sql variables types (which cant' be serialized), can
anyone share some practical solutions on how to go around this limitation?
In other words, how do you guys deal with numeric properties that can be
Null.

Thank you.

Nov 16 '05 #4
> Also note that in .NET 2.0 this will change.

What will change?
Nov 16 '05 #5
Hi,

You will have nullable types:
http://blogs.msdn.com/ericgu/archive...27/143221.aspx

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Rene" <no****@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Also note that in .NET 2.0 this will change.


What will change?

Nov 16 '05 #6

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

Similar topics

13
by: Eric Lilja | last post by:
Hello, consider the following complete program: #include <assert.h> #include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> static int...
20
by: Max Sandman | last post by:
I'm getting increasingly frustrated with C# and its exceptions on null values. Rather than try to deal with it on a hit-or-miss basis as exceptions pop up, I thought I should try to learn exactly...
1
by: Matt | last post by:
I could use some help dealing with null blobs. I'm returning a transaction from an Image BLOB field in SQL Server 2000 using C#. If the transaction exists the value is returned with out trouble,...
5
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
5
by: BobRoyAce | last post by:
Let's say I have a table called Users which has a field DeptID which is an int. I also have a User class which has a method for getting the data for a particular user (i.e. User with specified ID)...
3
by: afr0ninja | last post by:
Hello, I'm dealing with some order/inventory information where I need it in summary format so I can retain it, add to it without duplicating, and just make the reporting cleaner. I'll list an...
11
by: ronrsr | last post by:
I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text the encoding and collation is utf-8
12
by: GaryDean | last post by:
Is there any good way in which to deal with null datetimes. For instance, I can't seem to find anything that will pass a null value in a datetime parameter to another method. Convert.dbnull will...
3
by: sophie_newbie | last post by:
Hi, I want to store python text strings that characters like "é" "Č" in a mysql varchar text field. Now my problem is that mysql does not seem to accept these characters. I'm wondering if there...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.