Firsy of all, you do not set value for DateTimePicker:
dateTimePicker1.Text = dr["latedate"].ToString();
To set value, use
DateTimePicker.Value property[
^]:
dateTimePicker1.Value = dr["latedate"].Value;
If dr["latedate"].Value is equal
DbNull.Value[
^], you need to use simple trick:
dateTimePicker1.Value = dr["latedate"].Value ?? new DateTime(2000,1,1)
Above code should return
dr["latedate"].Value
or manually defined date.
Why you see:
26/56/2013
instead of
26/03/2013
? YAIR-I has answered to you in comment, but see the description of
DateTimePicker.CustomFormat[
^] property.
To properly set custom format, use:
public void SetMyCustomFormat()
{
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "dd/MM/yyyy";
}