My problem deals w/inserting nulls into database (SQL Svr 2K) for the
datetime fields activityDate and followUpDate where nulls are allowed.
From the web form, the user can type in/select the activity or followup
date.
If, for this exercise, the followupdate textfield is empty, then when
the insert method of the class calls the InsertActivityLog stored
procedure, how can I get nulls inserted instead of 1/1/1900 because of
the use of DateTime.MinValue when instantiating the ActivityLog obj.
BTW, even though the activityDate and followUpDate have values of
{1/1/1} before running the stored proc, it will fail w/an overflow msg
that date has be to from 1795 to etc. Once the SqlDateTime.Null is cast
as a DateTime, the activityDate var now has the value of 1/1/1900. I'd
like to be able to have a null entry in the ActivityDate field. Then
again, I've been staring at this problem too long and probably can't
see the solution...
Thanks in advance for suggestions/comments,
Rey
**********************************************
Below is the code snippet for the insert method.
if (activityDate == DateTime.MinValue)
activityDate = (DateTime)SqlDateTime.Null;
cmd.Parameters.Add("@ActivityDate", activityDate);
if (followUpDate == DateTime.MinValue)
followUpDate = (DateTime)SqlDateTime.Null;
cmd.Parameters.Add("@FollowUpDate", followUpDate);
Code snippet for getting values from various txtfields.
if (txtActivityDate.Text != string.Empty)
actLog.activityDate = DateTime.Parse(txtActivityDate.Text.Trim());
else
if (txtActivityDate.Text == string.Empty)
actLog.activityDate = DateTime.MinValue;