473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'System.DateTim e' and 'System.DBNull'

15 New Member
Hello,

I'm trying to send a Null value in a DateTime field while calling my stored procedure.

If I use this first method (short with one line), i got the following error message:

Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters["@p_order_date"].Value = (this.OrderDate == DateTime.MaxValue) ? DBNull.Value : this.OrderDate;
  2.  
Error Message:
Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTim e' and 'System.DBNull'


However, it works correctly if I use the 2nd method:

Expand|Select|Wrap|Line Numbers
  1. if (this.OrderDate == DateTime.MaxValue)
  2. {
  3. cmd.Parameters["@p_order_date"].Value = DBNull.Value;
  4. }
  5. else
  6. {
  7. cmd.Parameters["@p_order_date"].Value = this.OrderDate;
  8. }
  9.  

Can you help me to fix the problem with the first method ?

Thank you

Paul
Jan 20 '11 #1
0 1476

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5000
by: Darren Clark | last post by:
System.DateTime.Now it supposedly exists .. but doesnt seem to exist on my machine? How can i get the current date from the systme?
5
3937
by: Abdolhosein Vakilzadeh Ebrahimi | last post by:
Is there any way to construct a System.DateTime which doesn't check year, month and day to be in correct range== no validation? Thanks A.V.Ebrahimi
3
2782
by: andrewcw | last post by:
I save date time into my XML files like this: MesObj.theTime=System.DateTime.Now; "5/4/2004 8:50:30 AM" BUT that string is NOT recognizable as a valid dateTime when the data is read back from file ( i.e. schema strong data type dateTime It seems to follow this test protocal : DateTime transactDate = XmlConvert.ToDateTime(timeTest); I...
2
2634
by: Daniel | last post by:
how to get the number of milliseconds between two System.DateTime objects
4
35878
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
3
11992
by: Sugandh Jain | last post by:
Hi, I am using property like this.. private DateTime? _propName; public DateTime? PropName { get { return _propName; }
7
16642
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T...
2
10673
by: =?Utf-8?B?UHVyZSBIZWFydA==?= | last post by:
i use the following code to display date and time of system System.DateTime.Today.Now but it displayes seconds also haw can i make it display date and time without seconds and haw can it display time only with no date and without seconds also thank you --
4
5861
by: PeteOlcott | last post by:
I need to convert time_t to System::DateTime. All of the examples that I found are either in C# or in the obsolete managed C++ syntax. What is the current syntax for converting a (probably 64 bit) time_t value to System::DateTime ???
0
2786
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never was able to get the Millisecond from datacolumn. I explain the methods... 1) I created a Datatable that contain the column... then I fill a datarow...
0
7912
marktang
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...
0
8202
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, 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. ...
1
7959
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...
0
8216
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 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...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.