473,402 Members | 2,061 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,402 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 1643
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.