PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Insert Null Date

Reply

Insert Null Date

 
Thread Tools Rate Thread
Old 21-06-2006, 10:46 PM   #1
=?Utf-8?B?YW5u?=
Guest
 
Posts: n/a
Default Insert Null Date


How do I insert a null date into sql 2000? I tried this:

DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ?
DateTime.MinValue : DateTime.Parse(txtExpDate.Text);

and

DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ? null :
DateTime.Parse(txtExpDate.Text);

it doesn't accept nulls for DateTime, and the MinValue is not null.
Can anyone help please?
  Reply With Quote
Old 22-06-2006, 04:58 AM   #2
=?Utf-8?B?UmFq?=
Guest
 
Posts: n/a
Default RE: Insert Null Date

I guess that's not possible...what you have to do is if the date text box
field is null than set the date as '1/1/1900' and compare the date in Sql
Server if the value is same enter null value, otherwise the actual value.

Raj

"ann" wrote:

> How do I insert a null date into sql 2000? I tried this:
>
> DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ?
> DateTime.MinValue : DateTime.Parse(txtExpDate.Text);
>
> and
>
> DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ? null :
> DateTime.Parse(txtExpDate.Text);
>
> it doesn't accept nulls for DateTime, and the MinValue is not null.
> Can anyone help please?

  Reply With Quote
Old 22-06-2006, 12:10 PM   #3
Brendan Green
Guest
 
Posts: n/a
Default Re: Insert Null Date

Yes, it is.
Use System.DBNull.Value instead of a DateTime object.

"Raj" <Raj@discussions.microsoft.com> wrote in message
news:C6BE1738-4240-418A-8363-7060CF1848EC@microsoft.com...
>I guess that's not possible...what you have to do is if the date text box
> field is null than set the date as '1/1/1900' and compare the date in Sql
> Server if the value is same enter null value, otherwise the actual value.
>
> Raj
>
> "ann" wrote:
>
>> How do I insert a null date into sql 2000? I tried this:
>>
>> DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ?
>> DateTime.MinValue : DateTime.Parse(txtExpDate.Text);
>>
>> and
>>
>> DateTime expireDate = (txtExpDate.Text.Trim().Length <= 0) ? null :
>> DateTime.Parse(txtExpDate.Text);
>>
>> it doesn't accept nulls for DateTime, and the MinValue is not null.
>> Can anyone help please?



  Reply With Quote
Old 29-06-2006, 04:33 PM   #4
reza
Guest
 
Posts: n/a
Default Re: Insert Null Date

Have you ever tried to assign DBNull.Value to a DateTime variable in C#?
You can't!
  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off