473,403 Members | 2,284 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,403 software developers and data experts.

Assigning a null value in a dataset

Hi,

I'm writing a database programme with C# using a dataset. I want to set a DateTime for a particular
field of a row to null (nulls are allowed for that column). When I use:

newRow.Date_Pub=null;

I get a compile error: "Cannot convert null to 'System.DateTime' because it is a value type".

How do I set the field to null?
Aug 7 '06 #1
4 9713
John wrote:
Hi,

I'm writing a database programme with C# using a dataset. I want to set a DateTime for a particular
field of a row to null (nulls are allowed for that column). When I use:

newRow.Date_Pub=null;

I get a compile error: "Cannot convert null to 'System.DateTime' because it is a value type".

How do I set the field to null?
There should be newRow.SetDate_PubNull() method generated for the typed dataset.
Aug 7 '06 #2
Thanks, that works.

IIs there a way to set a SetDate variable to a special value that could represent null? This would
make it easier for me since I'm returning a DateTime from a function, and sometimes need to return
something that represents null.

Best wishes,

John
"Sericinus hunter" <se*****@flash.netwrote in message
news:OG**************@TK2MSFTNGP04.phx.gbl...
John wrote:
Hi,

I'm writing a database programme with C# using a dataset. I want to set a DateTime for a
particular
field of a row to null (nulls are allowed for that column). When I use:

newRow.Date_Pub=null;

I get a compile error: "Cannot convert null to 'System.DateTime' because it is a value type".

How do I set the field to null?
There should be newRow.SetDate_PubNull() method generated for the typed dataset.
Aug 7 '06 #3
"John" <-wrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
IIs there a way to set a SetDate variable to a special value that could
represent null? This would
make it easier for me since I'm returning a DateTime from a function, and
sometimes need to return
something that represents null.

You could use a DateTime as a nullable type:

private System.DateTime? GetDate(bool Condition) {
return Condition ? (System.DateTime.Now as System.DateTime?) :
null;
}
-- Alan
Aug 8 '06 #4
John wrote:
Thanks, that works.

IIs there a way to set a SetDate variable to a special value that could represent null? This would
make it easier for me since I'm returning a DateTime from a function, and sometimes need to return
something that represents null.
If you use .Net 2.0 then you can probably use nullable type.
I work with 1.1 and use DateTime.MinValue for this purpose.
Aug 8 '06 #5

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

Similar topics

2
by: WhiskyRomeo | last post by:
I have a bound textbox (bindings are set at design time) to a dataset column. Sometimes the value of this textbox must be set so that the underlying database field gets updated to null when using...
1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
0
by: gilly3 | last post by:
Reposting to a more relevant group. I am passing a generic dataset into a new XMLDataDocument and then parsing the XML with XSLT. The idea being that I can parse any dataset with the same xslt,...
8
by: Woody Splawn | last post by:
Lets say I have a winform that is populated with a dataset. The dataset and data table may have several rows in it. Lets say I am looking at the winform and I want to assign a value to a certain...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
9
by: GotDotNet? | last post by:
I have a dataset and I have to loop through it and some of the values for an insertition into the db. Some of the fields are integers and booleans but contain a NULL in the field. how can I...
3
by: Froefel | last post by:
Hi group I am creating a web application that uses a simple DAL as an ObjectDataSource. To retrieve data from the database, I use a DataReader object from which I then assign the various fields...
7
by: monika varshney | last post by:
I have to read a database using dataset. My database has some null values. My code is working fine when there is a value in the database. But when there is a null value in the database, dataset...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.