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" <
[email protected]>
| References: <#
[email protected]>
<
[email protected]>
| 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: <
[email protected]>
| 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!TK2MSFTNGP11.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
|
| | > 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" <
[email protected]>
| > | 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: <#
[email protected]>
| > | 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!TK2MSFTNGP10.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
| > |
| > |
| > |
| >
|
|
|