I want to store a DateTime.Now from my WPF C# application to a DateTime column in SQL CE Database.
I am inserting DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss") then I get the following error:
String was not recognized as a valid DateTime.Couldn’t store <2011-54-06 18:54:47> in DateTime Column. Expected type is DateTime.
How to store DateTime in a specific format to SQL CE?
[EDIT]
Correction made to: DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
However, after I insert and populate the data to a DataGrid. It shows 2011-54-06 18:54:47 in stead of yyyy-MM-dd HH:mm:ss format. I specify the format to be insert to database but it seem SQL CE has its own way of storing. Why?
You just change the
yyyy-mm-dd HH:mm:ssin toyyyy-MM-dd HH:mm:ss. Obviously it will show like that.Because, you are not inserting the Month but a minute. So, the Datetime is not converted from string format due to wrong format.