Saturday, January 15, 2011

Cannot convert value of the paramter from System.String to System.DateTime

There is a very annoying bug in Visual Studio 2005 when you work with GridView and ObjectDataSource ( my customer has an old environment - sorry ).

What's the deal ?

When you try to update any data which is visible in the GridView/ObjectDataSource you might get the error in the title.

What's the cause for that ?

By default, the checking of the dates is being done according to the US format ( MM-DD-YY ). Hence, when you after the 12th day of the month and your system work with EU format ( DD-MM-YY ) , you will get the error in the title.

How to work around that ?

You will have to configure in your Aspx page, under the object data source definition the parameters you are using including their type. In that case, it will take on runtime the local date format, and you won't have the problem I mentioned before.


Example :
 











Hope it helps! It solved my issue.