DateTime fields and DBNull.Value

G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top