New to Telerik UI for WinFormsStart a free 30-day trial

Handle MySqlDateTime object while populating RadGridView from MySQL Database

Updated over 6 months ago

Environment

Product VersionProductAuthor
2022.1.222RadGridView for WinFormsDinko Krastev

Description

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:

Solution

C#
 
RadGridView1.Columns["Entered Date Time"].DataType = typeof(DateTime);
RadGridView1.Columns["Date of Birth"].DataType = typeof(DateTime);              
       
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support