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.DateTim e' because it is a value
type"
How can this be done? 3 1920
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<DateTi me>. 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.MinVal ue). Alternatively, use an extra bool field to
indicate null.
HTH,
Kent
"Daves" <db****@simnet. is> wrote in message
news:OX******** ******@TK2MSFTN GP15.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.DateTim e' because it is a value type"
How can this be done?
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****@interno de.on.net> a écrit dans le message de news:
%2************* ***@TK2MSFTNGP1 1.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<DateTi me>. 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.MinVal ue). Alternatively, use an extra bool field to indicate null.
HTH, Kent
"Daves" <db****@simnet. is> wrote in message news:OX******** ******@TK2MSFTN GP15.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.DateTim e' because it is a value type"
How can this be done?
thx guys, I think I have c# v2, both of your solutions are great.
"Vivek" <vi************ **@msn.com> wrote in message
news:eV******** ******@TK2MSFTN GP10.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****@interno de.on.net> a écrit dans le message de news: %2************* ***@TK2MSFTNGP1 1.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<DateTi me>. 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.MinVal ue). Alternatively, use an extra bool field to indicate null.
HTH, Kent
"Daves" <db****@simnet. is> wrote in message news:OX******** ******@TK2MSFTN GP15.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.DateTim e' because it is a value type"
How can this be done?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 have a value of DateTime with it. I tried calling the method with
null params but that didn't work because DateTime is a struct.
but I don't want to assign any values to it... because eventally the
|
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 Posting, so would I do
this in the PostingObject Constructor?
Here is my code:
using System;
using System.Collections;
using Microsoft.ContentManagement.Publishing;
|
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 forward to check another value, the method returns false, although the
value is contained in the dataTable (DateTime values). So the loop goes and
goes ...
|
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 resulting date and time to get the specific filename and path from the same DataTable.
The problem is that this worked fine on my Windows XP machine, but did not work on any of several Windows 2000 computers at the client's location. The Select...
|
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 have added 3 records to the table and ran the
program but it fails with the error above.
The application is supposed to create the hashtable of records as a
static feature which will be permanently available to my application.
To demonstrate that...
| |
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 the web server every day. Since I don't want the
application to time-out, I'm putting all this into a Server-Side
Asynchronous Web Method.
I've starting out by writing this test web service:
|
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) : base(message){}
public FtpException(string message, Exception innerException) :
base(message,innerException){}
|
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 denominator for structs and strings
and while looking through the SDK I only noticed the IEquatable<T>
interface.
So I implemented the class with methods such as the following, but I'm aware
that this is not the right approach.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |