1

I am trying to get the date from the database fields. If the date is not found it goes to a function where the string is set to " / / " based on "DD/MM/YYYY" format.

Public Overrides Property Text() As String
    Get
        Return MyBase.Value.ToString(MyBase.CustomFormat)
    End Get
    Set(ByVal value As String)
        MyBase.Text = value
    End Set
End Property

MyBase.Text = value

This is where the error occurs when I am trying to set value to MyBase.Text MyBase is set to System.Windows.Forms.DateTimePicker. All I want to do is that if the Date doesn't exist I want to set the value to " / / ". Any suggestions as I've been trying to figure a way to work with it with minimal code changes to my application.

  • What is the relationship between the database field and the DateTimePicker? – Andrew Morton Mar 19 '20 at 21:33
  • Does this answer your question? [How can I make a DateTimePicker display an empty string?](https://stackoverflow.com/questions/846395/how-can-i-make-a-datetimepicker-display-an-empty-string) – Ruud Helderman Mar 19 '20 at 21:37
  • My advice to keep you from burning in date format hell: don't use strings to store dates. If you really must, then use a decent date parser to convert them to (nullable) `DateTime` before passing them on to the next layer (in this case, `DateTimePicker`). – Ruud Helderman Mar 19 '20 at 21:40
  • 1
    @RuudHelderman No that does not help my situation. Some Fields return a proper date and they go through the code without any errors. The error only occurs when the database does not have a set date in the field so it tries to make it " / / " which gives me the error. – Snehil Maknojia Mar 19 '20 at 21:54

0 Answers0