0

I'm working on a small application. I want to set today's value as the default value to the datetimepicker. Therefore used the form_load event and set the date like this:

DateDateTimePicker.Value = Date.Today

If I select a date from the picker it works fine. But if I don't it shows a null exception when saves it.

The exception occurs in

Me.SaleBindingSource.EndEdit()

Exception is

'System.Data.NoNullAllowedException'
stakx - no longer contributing
  • 77,057
  • 17
  • 151
  • 248
Choxmi
  • 1,304
  • 3
  • 22
  • 38
  • You need to be more specific, and to show the code that makes you say "it shows a null exception when saves it". You probably mean a "NullReferenceException". In that case, note that almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jun 21 '15 at 05:57
  • Sorry about that. I have 'System.Data.NoNullAllowedException' and it occurs in 'Me.SaleBindingSource.EndEdit()' – Choxmi Jun 21 '15 at 06:01
  • Your call to EndEdit() commits the changes, and one of the committed values is null – Y.S Jun 21 '15 at 06:24
  • Yes. Thank u. Value is the date value. If i keep it default I get the error msg. :-( – Choxmi Jun 21 '15 at 08:43
  • Is there some other variable which is dependent on a value being picked in the DTP rather than the value of the DTP? – Andrew Morton Jun 21 '15 at 21:54

1 Answers1

0

You cant have null in datetimepicker but set it to datetime.min value and tgen perform validations

Avneesh
  • 654
  • 4
  • 6