Solved

How do I default to NULL in Date Time Picker, when there is no applicable date in vb.net

Posted on 2016-10-25
9
59 Views
Last Modified: 2016-10-25
I'm using a Date Time Picker. There will not always be a need to select a Date. I would like that entry to default to NULL in the Sql database.
so in other words I would like to give the user an option to select or not select.
can anyone share sample vb.net code that would allow me to default to NULL in Date Time Picker, when there is no applicable date, thank you
0
Comment
Question by:fadiel ras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41858275
hi Fadiel,

so in other words I would like to give the user an option to select or not select
if you're calling a stored procedure, try to make sure that parameter is optional with default value as NULL.

then from your coding, when the date time picker was not being used, just do not pass that parameter to your stored procedure. let the stored procedure to detect whether a value is passed into it.
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41858278
You can SET the parameter to NULL in stored procedure like

CREATE Proc ProcName
(
   a DateTime NULL...
)
AS..

In the above case the you dont pass the value to datetime, SP will automatically handle it.
0
 

Author Comment

by:fadiel ras
ID: 41858284
Thanks Gents!
yes I am using a Stored Proc and the Sql Column does allow NULL.

So the record saves back to the database, however is saves as "1900-01-01" instead of NULL
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41858286
So the record saves back to the database, however is saves as "1900-01-01" instead of NULL
how's your vb.net codes look like?
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41858289
Yes default it will save 1900-01-01 as the default date in the column. Try...below..

INSERT INTO [pawan] ([c],[date])
VALUES ('111',NULL)
0
 

Author Comment

by:fadiel ras
ID: 41858291
something like:

                        If IsDBNull(dr.Cells("EffectiveToDate").Value)  Then
                            AddParm("@EffectiveToDate", DBNull.Value.ToString, DbType.String)
                        Else
                            AddParm("@EffectiveToDate", Trim(Replace(dr.Cells("EffectiveToDate").Value.ToString.ToUpper, "'", "")), DbType.String)
                        End If

Open in new window

0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41858292
try this instead:

                        If IsDBNull(dr.Cells("EffectiveToDate").Value)  = false Then
                           AddParm("@EffectiveToDate", Trim(Replace(dr.Cells("EffectiveToDate").Value.ToString.ToUpper, "'", "")), DbType.String)
                        End If

Open in new window

0
 

Author Closing Comment

by:fadiel ras
ID: 41858297
Solved. Thank you Mr Chong (you genius)
0
 

Author Comment

by:fadiel ras
ID: 41858298
Thanks Pawan, Thanks Ryan. appreciate that...saved me a few hours, I'm sure
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question