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

method should return DateTime but I want it to return null

a get { ... } for public property SelectedValue returns DateTime type to be
used as a parameter in a Sql update query but I'd like it to return "empty"
if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?
Jan 31 '06 #1
3 1886
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See the
Nullable API doc for more details. If you're using C# 1.0 then you'll need
to either store in a reference type (object) or pick a DateTime to equate to
null (eg. DateTime.MinValue). Alternatively, use an extra bool field to
indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to be
used as a parameter in a Sql update query but I'd like it to return "empty"
if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?

Jan 31 '06 #2
You can also send the datetime var with out parameter and get the boolean
result like this :

bool Fx(out varDateTime)
{
//return bool;
}
if bool is true, varDateTime is not null

Vivek

Le relais des Artistes (Esvicom - Lieu de Vie, ATBM - Théâtre du Bout des
Mains, DW Home Studio) vous souhaite une très bonne année 2006
http://www.relaisdesartistes.com
"Kent Boogaart" <ke****@internode.on.net> a écrit dans le message de news:
%2****************@TK2MSFTNGP11.phx.gbl...
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See the
Nullable API doc for more details. If you're using C# 1.0 then you'll need
to either store in a reference type (object) or pick a DateTime to equate
to null (eg. DateTime.MinValue). Alternatively, use an extra bool field
to indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to
be used as a parameter in a Sql update query but I'd like it to return
"empty" if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?


Jan 31 '06 #3
thx guys, I think I have c# v2, both of your solutions are great.

"Vivek" <vi**************@msn.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
You can also send the datetime var with out parameter and get the boolean
result like this :

bool Fx(out varDateTime)
{
//return bool;
}
if bool is true, varDateTime is not null

Vivek

Le relais des Artistes (Esvicom - Lieu de Vie, ATBM - Théâtre du Bout des
Mains, DW Home Studio) vous souhaite une très bonne année 2006
http://www.relaisdesartistes.com
"Kent Boogaart" <ke****@internode.on.net> a écrit dans le message de news:
%2****************@TK2MSFTNGP11.phx.gbl...
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See
the Nullable API doc for more details. If you're using C# 1.0 then you'll
need to either store in a reference type (object) or pick a DateTime to
equate to null (eg. DateTime.MinValue). Alternatively, use an extra bool
field to indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to
be used as a parameter in a Sql update query but I'd like it to return
"empty" if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?



Jan 31 '06 #4

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

Similar topics

7
by: Abhishek Srivastava | last post by:
Hello All, I am facing a simple problem. I have a method which accepts two parameters. Both are of type DateTime. However when calling this method there are times when the caller does not...
0
by: John Haigh | last post by:
Should possibly have an "add" method in a PostingObject class in the constructor of PostingObject. will call to add a Posting to the ? Does this make sense? My sense is that a PostingObject needs a...
6
by: Millo | last post by:
Hi I'm trying to call the method Contains in a loop: out of the loop I set the primary key of the dataTable. The method returns true one time at a certani value, but then, when the loop steps...
0
by: Vagabond Software | last post by:
I posted this problem earlier and now have more information. I use the DataTable Select method to get find the most recent "LastModified" date in a table of similarly named files. I then use the...
3
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I...
0
by: Simple Simon | last post by:
Hi, excuse the long post and plz read on :) My web application needs to upload a .csv & .zip file, as well as, import the .csv into a (Sql2000) table and unzip the .zip file to a directory on...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
5
by: Anders Borum | last post by:
Hi! While implementing a property manager (that supports key / value pairs), I was wondering how to constrain T to a struct or string type. Basically, I guess what I'm looking for is the common...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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?
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...

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.