Connect with Expertise | Find Experts, Get Answers, Share Insights

Assigning a null value in a dataset

John
 
Posts: n/a
#1: Aug 7 '06
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?



Sericinus hunter
 
Posts: n/a
#2: Aug 7 '06

re: Assigning a null value in a dataset


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.
John
 
Posts: n/a
#3: Aug 7 '06

re: Assigning a null value in a dataset


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.


Alan Pretre
 
Posts: n/a
#4: Aug 8 '06

re: Assigning a null value in a dataset


"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


Sericinus hunter
 
Posts: n/a
#5: Aug 8 '06

re: Assigning a null value in a dataset


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.
Closed Thread