New to Telerik UI for WinForms? Download free 30-day trial

Handle MySqlDateTime object while populating RadGridView from MySQL Database


Product Version Product Author
2022.1.222 RadGridView for WinForms Dinko Krastev


When your connection string contains ConvertZeroDateTime is set to true, invalid objects from the database are being converted to .NET System.DateTime.MinValue object, and as RadGridView knows how to work with System.DateTime is being handled correctly.

However, when AllowZeroDateTime is set to true in the connection string, invalid objects from the database are being sent as MySqlDateTime object. In this case, RadGridView does not know about such type of object, hence it falls back to creating a text box column for it and the column data type is being set to string. To make it work we can change the column data type to DateTime and the dates will be shown correctly:


RadGridView1.Columns["Entered Date Time"].DataType = typeof(DateTime);
RadGridView1.Columns["Date of Birth"].DataType = typeof(DateTime);              

RadGridView1.Columns("Entered Date Time").DataType = GetType(DateTime)
RadGridView1.Columns("Date of Birth").DataType = GetType(DateTime)    

In this article