2018年2月26日 星期一

c# retrieve datetime field from sqlite when you have an error "String was not recognized as a valid DateTime."

"String was not recognized as a valid DateTime." This error is caused by the data string which you save in the database with wrong formate. for solving this error, you just need to adjust you data string to follow the formate as "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd HH:MM:SS.sssss" if you have ms information need to save. 發生錯誤 "String was not recognized as a valid DateTime." 是因為在sqlite 資料庫中的時間資料字串格式無法讓C#的物件解讀造成的。所以只要將存入的資料,修改成符合C#需要的時間格式即可順利運作。符合的資料格式為"yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd HH:MM:SS.sssss" 如果你有ms的時間資訊需要填入。

沒有留言: