PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

DateTime fields and DBNull.Value

 
 
=?Utf-8?B?V2lsa2VyIFNoYW5lIEJydWNl?=
Guest
Posts: n/a
 
      31st Jan 2005
I have a stored procedure that has a couple of DateTime parameters that are
used to update nullable DateTime columns in one of my tables. When I call
the stored procedure using ADO.NET in C# from an OdbcCommand object and
attempt to set the DateTime parameters to null, I am getting the following
exception message: "String was not recognized as a valid DateTime."

The calling code for the parameters in question has the following form:

parm = command.Parameters.Add("@myDate", OdbcType.DateTime);
parm.Direction = ParameterDirection.Input;
parm.Value = DBNull.Value;

The exception occurs when executing command.ExecuteNonQuery(), A display of
the exception stacktrace shows that the exception is thrown within the Parse
method of the System.DateTimeParse class before a call is made to the stored
procedure. Can anyone give me some guidance as to why the system is trying
to perform a parse on a field that has been set to the DBNull.Value?

Thanks in advance for any assistance you can provide.

Wilker Shane Bruce, Ph.D.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Vmljbw==?=
Guest
Posts: n/a
 
      4th May 2005
You may want to take a look on this link
http://msdn.microsoft.com/library/de...valuetopic.asp

Specially on the paragraph:
"Data intensive applications accessing SQL databases must use the
System.Data.SqlTypes classes, which have inherent support for null values."

"Wilker Shane Bruce" wrote:

> I have a stored procedure that has a couple of DateTime parameters that are
> used to update nullable DateTime columns in one of my tables. When I call
> the stored procedure using ADO.NET in C# from an OdbcCommand object and
> attempt to set the DateTime parameters to null, I am getting the following
> exception message: "String was not recognized as a valid DateTime."
>
> The calling code for the parameters in question has the following form:
>
> parm = command.Parameters.Add("@myDate", OdbcType.DateTime);
> parm.Direction = ParameterDirection.Input;
> parm.Value = DBNull.Value;
>
> The exception occurs when executing command.ExecuteNonQuery(), A display of
> the exception stacktrace shows that the exception is thrown within the Parse
> method of the System.DateTimeParse class before a call is made to the stored
> procedure. Can anyone give me some guidance as to why the system is trying
> to perform a parse on a field that has been set to the DBNull.Value?
>
> Thanks in advance for any assistance you can provide.
>
> Wilker Shane Bruce, Ph.D.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml, DateTime conversions and DateTime fields Andy B Microsoft ASP .NET 2 25th Sep 2008 02:43 PM
DBNULL to DATETIME Jose Fernandez Microsoft C# .NET 4 18th Oct 2006 05:00 PM
DateTime to DBNull.Value =?Utf-8?B?RGlvZ28gQWx2ZXMgLSBTb2Z0d2FyZSBEZXZlbG9w Microsoft C# .NET 2 30th Sep 2005 04:03 PM
Format grid column to display "" instead of datetime DBNull (1/1/1 =?Utf-8?B?Q2FybG9zIExvemFubw==?= Microsoft C# .NET 4 27th Jul 2005 12:16 AM
Setting a DateTime Parameter to DBNULL.Value =?Utf-8?B?bWljaGFlbA==?= Microsoft ADO .NET 3 30th Sep 2004 03:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:56 AM.