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

DBNull issue

DG
I have my object containing datarow and exposing properties:
e.g.:

public int Price
{
get{
return _myRow.Price;
}
set{
_myRow.Price = value;
}
}

what if i want to set this value to null?

Do i have to expose .SetPriceNull() and .IsPriceNull()
for each numeric/date property?
Is there more elegant way?

May 25 '06 #1
3 1641
Have you looked at Nullable<T> in 2.0?

just use "int?" instead of "int"

This allows it to act as "null" - not quite the same as DBNull, but many
controls will know what you mean...

Marc
May 25 '06 #2
DG
Thanx this is what i need.
How to set 'int?' variable to DBnull?
will dataAdapter understand that and update database field to null?
"Marc Gravell" <ma**********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Have you looked at Nullable<T> in 2.0?

just use "int?" instead of "int"

This allows it to act as "null" - not quite the same as DBNull, but many
controls will know what you mean...

Marc

May 25 '06 #3
int? can accept null or an integer. Since you are using getters and setters
to an object with DBNull, one approach here would be to change between null
and DBNull in the getter / setters, presumably with the "a ? b : c" tertiary
syntax.

I don't use typed data-sets much, so I'm inferring the following from your
e-mail; it might actually need "is DBNull" or something similar instead...
but give it a whirl...

Marc

public int? Price
{
get{
return _myRow.IsPriceNull() ? null : _myRow.Price;
}
set{
if(value==null)
_myRow.SetPriceNull();
else
_myRow.Price = value;
}
}
May 25 '06 #4

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

Similar topics

2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
4
by: Carlos Lozano | last post by:
Hello Folks! I have a grid that populates from a table on SQL Server. All datetime with DBNull value show 1/1/1900 12:00AM ... Instead of just blank (""). I found a document with the following...
11
by: Patrick.O.Ige | last post by:
When i try and use this (Where Unit is a column in my Table):- If Unit Is DBNull.Value Then Return "1" Else Return "2" End If I always have 2 returned! Even when Unit is NULL! I want a...
4
by: Tina | last post by:
I have instantiated an insertRow for a dataset. I now want to make the GLCode DBNull. I have tried: insertRow.GLCode = Convert.dbnull insertRow.GLCode = Convert.dbnull(insertRow.GLCode) and...
10
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
0
by: =?Utf-8?B?Y2NfY3Jhc2g=?= | last post by:
Hello all, This is probably a simple issue but since I am a newbie I am really stuck on it. I have been developing some code and I was using rowPosition to pull data from a Access Data base and...
2
by: =?Utf-8?B?TWlrZSBPS0M=?= | last post by:
VB 2005 All developers face this issue; so I'm sure Microsoft was a solution for it. What is the built in method to check DBNull in a recordset field? NOT a typed dataset. I don't want to...
2
by: pvong | last post by:
Doing this in VB.NET I have a gridview RowDataBound. I want to do a test on each row column (12). Some of the rows have NULL value. This is the error message I'm getting. Object cannot be...
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: 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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.