473,889 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 13000
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*****@mindsp ring.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.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 0-1pool36-160.nas14.milwa ukee1.wi.us.da. qwest.net
63.156.36.160
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:156742
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.mic rosoft.com> wrote in message
news:S7******** ******@cpmsftng xa06.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*****@mindsp ring.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.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 0-1pool36-160.nas14.milwa ukee1.wi.us.da. qwest.net
63.156.36.160
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:156742
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.DateT ime, 8);
p.Value = System.DBNull.V alue;

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

--------------------
| From: "Dean Slindee" <sl*****@mindsp ring.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.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 0-1pool36-60.nas14.milwau kee1.wi.us.da.q west.net
63.156.36.60
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:156939
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.mic rosoft.com> wrote in message
| news:S7******** ******@cpmsftng xa06.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*****@mindsp ring.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.publi c.dotnet.langua ges.vb
| > | NNTP-Posting-Host: 0-1pool36-160.nas14.milwa ukee1.wi.us.da. qwest.net
| > 63.156.36.160
| > | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| > | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:156742
| > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1648
by: Evgeny Gopengauz | last post by:
What is the way recommended by Microsoft for distributing the MSSQL database with end-user application if I don't like to use sql-scripts because I need to hide the stored procedures sources (they are marked as "encrypted")? Backup/restore? Or something else? *** Sent via Developersdex http://www.developersdex.com ***
1
1439
by: Edward King | last post by:
I have a statement in a asp,like follows£º var str=window.top.main.document.all.contenttext.value; I use IIS5.0 to deploy this asp,then I visit this asp like follows: http://localhost/test/default.asp I found I can get this page,then I use my computer's IP address, http://192.168.0.3/test/default.asp I got errors! It said "no right"£¬then I erase this statement,then I visit
44
9474
by: Viken Karaguesian | last post by:
Hello all, On occasion I want to open hyperlinks (images, etc.) in a new window. In the past, I've used target="_blank" to open the link in a new window. However, using the "target" attribute causes my pages to fail validation (strict doctype). The validator says "There is no attribute 'target'.." So...how do I open a link in a new window, without Javscript, and pass strict validation?
1
8059
by: tshad | last post by:
I have columns with text and radio buttons that I would like to center or put to the right of the cell, but the attribute ItemStyle-HorizontalAlign="right" doesn't seem to work. <asp:TemplateColumn HeaderText="Job Board" Visible="true" ItemStyle-Width="150px" HeaderStyle-Width="150px" ItemStyle-VerticalAlign="middle" ItemStyle-HorizontalAlign="right"> <itemtemplate> asp:Label ID="JobBoardName" Text='<%#
7
10896
by: the_grove_man | last post by:
How do I invoke a "Right-Click" Programmtically? John
3
8778
by: mehdi | last post by:
I have a field that is a memo and I have a report displaying the text in that memo. What I need to know is how to "justify" the text right to left. The reason is in arabic and persian language we write right to left. What I want:
8
4639
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this "3145728". But the MouseButtons Enum contains only Left, Right, Middle, None, XButton1 and XButton2. I am using .NET 1.1 version. How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right click not added to the Enum? Can anyone help me?
2
1742
by: Tom P. | last post by:
I am writting a extended ListView control and I'd like to stop the default behavior when a user right-clciks on a non-label area and then drags causing a "marching ants" selection box to appear. First, what event is this? And second, how do I stop it? I've trapped the OnItemDrag and OnDragEnter events and it's not them (OnDragEnter doesn't even fire). In OnClick I test for right-click and simply return.
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11198
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10889
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9609
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.