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

'System.DateTime' and 'System.DBNull'

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.DateTime' 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 1456

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

Similar topics

3
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
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
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...
2
by: Daniel | last post by:
how to get the number of milliseconds between two System.DateTime objects
4
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
by: Sugandh Jain | last post by:
Hi, I am using property like this.. private DateTime? _propName; public DateTime? PropName { get { return _propName; }
7
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...
2
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...
4
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)...
0
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.