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
27 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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 16

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
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
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
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
Comment Utility
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 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
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
Comment Utility
Solved. Thank you Mr Chong (you genius)
0
 

Author Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now