0

I created a Search in vb.net button that allows me to display the elements of my table 'book' with as properties (code_ouvrage,id, title book, publishing house and date of edition) now I would like that when I do the search that the value of date of edition (which is of type date format 0000/00/00 is displayed in the DateTimePicker1. I already tried this:

DateTimePicker1.Value = dtr("date").ToString 

I was waiting for him to return the date value in my MySQL database that he will display in the DateTimePicker.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939

1 Answers1

0

I don't know if I understand the question right. But if you want to put date value to datetimepicker, you can do something like that:

If Not IsDBNull(dtr("date")) Then
   DateTimePicker1.Value = CDate(dtr("date"))
End If

I hope it was helpful.

EDITED:

As you asked me, you also need to check if the date is Nothing:

If Not IsDBNull(dtr("date")) AndAlso dtr("date") IsNot Nothing Then
    DateTimePicker1.Value = CDate(dtr("date"))
End If

Checking if date Is Nothing Is equivalent to check if a Date is Date.MinValue. The value 01/01/0001 00:00:00is the minimum value of Date.

Antolin11
  • 51
  • 7
  • i do it and get this error : System.ArgumentOutOfRangeException : 'La valeur '01/01/0001 00:00:00' n'est pas valide pour 'Value'. 'Value' doit être compris entre 'MinDate' et 'MaxDate'. Nom du paramètre : Value' – Cheikh Diallo May 25 '23 at 17:46
  • Sorry @CheikhDiallo I forget to check if the date is Nothing (in VB is equivalent to Date.MinValue). I have modified the answer to solve this. – Antolin11 May 26 '23 at 07:16