363,924 Members | 2598 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Assigning a null value in a dataset

John
P: n/a
John
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
Share this Question
Share on Google+
4 Replies


Sericinus hunter
P: n/a
Sericinus hunter
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

John
P: n/a
John
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" <serhunt@flash.netwrote in message
news:OG$2QomuGHA.5076@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

Alan Pretre
P: n/a
Alan Pretre
"John" <-wrote in message news:%23vriNAnuGHA.3264@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

Sericinus hunter
P: n/a
Sericinus hunter
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

Post your reply

Help answer this question



Didn't find the answer to your C# / C Sharp question?

You can also browse similar questions: C# / C Sharp