PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert Null Date
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert Null Date
![]() |
Insert Null Date |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Have you ever tried to assign DBNull.Value to a DateTime variable in C#?
You can't! |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

