469,568 Members | 1,358 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

"right" way to handle null date values?

I am looking for the "right" way to handle inserting and presenting null
date values.
Public Const c_NullDate As Date = #12:00:00 AM#
If I set the value of a date variable in an SQL Server insert statement to
c_NullDate, the insert statement works. When I re-read the row and display
the inserted date value in a text box, the string "1/1/1900" is displayed.
If one wanted the textbox to display an empty string, how should either the
insert to the db be handled, or should code to show a blank string in the
text box be added?

Thanks

Dean Slindee
Nov 20 '05 #1
6 12733
Hi Dean,

Generally, when you want to assign a null value to the data type, you can
use DBNull.Value. In database, the field will be marked as <null>. When you
bind the data source to a textbox, the textbox will display an empty string
if the value of the field is DBNull.Value.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Dean Slindee" <sl*****@mindspring.com>
| Subject: "right" way to handle null date values?
| Date: Thu, 13 Nov 2003 22:15:17 -0600
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#n**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-1pool36-160.nas14.milwaukee1.wi.us.da.qwest.net
63.156.36.160
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156742
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I am looking for the "right" way to handle inserting and presenting null
| date values.
| Public Const c_NullDate As Date = #12:00:00 AM#
| If I set the value of a date variable in an SQL Server insert statement to
| c_NullDate, the insert statement works. When I re-read the row and
display
| the inserted date value in a text box, the string "1/1/1900" is displayed.
| If one wanted the textbox to display an empty string, how should either
the
| insert to the db be handled, or should code to show a blank string in the
| text box be added?
|
| Thanks
|
| Dean Slindee
|
|
|

Nov 20 '05 #2
Value of type 'System.DBNull' cannot be converted to 'Date'.

is returned by the VS.Net source editor. Still wishing for a way to insert
a null

value into a date field and subsequently into a date column in SQLServer.

Currently inserts '1/1/1900'

Thanks,

Dean Slindee

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:S7**************@cpmsftngxa06.phx.gbl...
Hi Dean,

Generally, when you want to assign a null value to the data type, you can
use DBNull.Value. In database, the field will be marked as <null>. When you bind the data source to a textbox, the textbox will display an empty string if the value of the field is DBNull.Value.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Dean Slindee" <sl*****@mindspring.com>
| Subject: "right" way to handle null date values?
| Date: Thu, 13 Nov 2003 22:15:17 -0600
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#n**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-1pool36-160.nas14.milwaukee1.wi.us.da.qwest.net
63.156.36.160
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156742
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I am looking for the "right" way to handle inserting and presenting null
| date values.
| Public Const c_NullDate As Date = #12:00:00 AM#
| If I set the value of a date variable in an SQL Server insert statement to | c_NullDate, the insert statement works. When I re-read the row and
display
| the inserted date value in a text box, the string "1/1/1900" is displayed. | If one wanted the textbox to display an empty string, how should either
the
| insert to the db be handled, or should code to show a blank string in the | text box be added?
|
| Thanks
|
| Dean Slindee
|
|
|

Nov 20 '05 #3
Hi Dean,

Please make sure to use DBNull.Value instead of DBNull. DBNull.Value cannot
be assigned to a DateTime object. However, it has to be assigned to the
value of a sqlParameter. Please try the following code.

SqlParameter p = new SqlParameter("@ParaName", SqlDbType.DateTime, 8);
p.Value = System.DBNull.Value;

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Dean Slindee" <sl*****@mindspring.com>
| References: <#n**************@TK2MSFTNGP10.phx.gbl>
<S7**************@cpmsftngxa06.phx.gbl>
| Subject: Re: "right" way to handle null date values?
| Date: Fri, 14 Nov 2003 12:36:23 -0600
| Lines: 72
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <Ob*************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-1pool36-60.nas14.milwaukee1.wi.us.da.qwest.net
63.156.36.60
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156939
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Value of type 'System.DBNull' cannot be converted to 'Date'.
|
| is returned by the VS.Net source editor. Still wishing for a way to
insert
| a null
|
| value into a date field and subsequently into a date column in SQLServer.
|
| Currently inserts '1/1/1900'
|
| Thanks,
|
| Dean Slindee
|
| "Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
| news:S7**************@cpmsftngxa06.phx.gbl...
| > Hi Dean,
| >
| > Generally, when you want to assign a null value to the data type, you
can
| > use DBNull.Value. In database, the field will be marked as <null>. When
| you
| > bind the data source to a textbox, the textbox will display an empty
| string
| > if the value of the field is DBNull.Value.
| >
| > If anything is unclear, please feel free to reply to the post.
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
| >
| > --------------------
| > | From: "Dean Slindee" <sl*****@mindspring.com>
| > | Subject: "right" way to handle null date values?
| > | Date: Thu, 13 Nov 2003 22:15:17 -0600
| > | Lines: 15
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Message-ID: <#n**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.vb
| > | NNTP-Posting-Host: 0-1pool36-160.nas14.milwaukee1.wi.us.da.qwest.net
| > 63.156.36.160
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156742
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > |
| > | I am looking for the "right" way to handle inserting and presenting
null
| > | date values.
| > | Public Const c_NullDate As Date = #12:00:00 AM#
| > | If I set the value of a date variable in an SQL Server insert
statement
| to
| > | c_NullDate, the insert statement works. When I re-read the row and
| > display
| > | the inserted date value in a text box, the string "1/1/1900" is
| displayed.
| > | If one wanted the textbox to display an empty string, how should
either
| > the
| > | insert to the db be handled, or should code to show a blank string in
| the
| > | text box be added?
| > |
| > | Thanks
| > |
| > | Dean Slindee
| > |
| > |
| > |
| >
|
|
|

Nov 20 '05 #4
Hi Dean,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help on this? I'm still monitoring on it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 20 '05 #5

Kevin,
Have you checked the field for DBNULL? Hope this will help you out.

http://msdn.microsoft.com/library/de...classtopic.asp

Kevin Yu [MSFT] wrote:
Hi Dean,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help on this? I'm still monitoring on it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Nov 20 '05 #6
Thank you, Jacky. I have checked that.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Edward King | last post: by
44 posts views Thread by Viken Karaguesian | last post: by
1 post views Thread by tshad | last post: by
7 posts views Thread by the_grove_man | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.