Recently I used ASP. NET + SQLite database to develop a website. Program As a result, there was a headache in date processing:
Note: An error occurred while executing the current Web request. Check the stack trace information to learn about this error and Code Detailed information about the cause of the error.
Exception details: System. formatexception: the string is not recognized as a valid datetime.
Solution:
Converts a type when the date is saved to the SQLite database, for example, string _ now = system. datetime. Now. tostring ("S ");
That is to say, adding s to the. tostring () method solves the problem of date reading errors.
Simple code example:
String _ indate = request ["indate"]; // The input date, for example, 2009-2-21
Datetime _ intime = convert. todatetime (_ indate );
// The SQL statement for saving data is as follows:
Insert into table (indate) values ('"+ _ intime. tostring (" S ") +"'); // convert
Because ISO 8601 Description: (http://msdn.microsoft.com/zh-cn/library/ms187819.aspx)
A string example is provided:
* 2004-05-23t14: 25: 10
* 2004-05-23t14: 25: 10.487
Therefore, the date saved by SQLite must be converted to ISO 8601 standard string format.
Use date. tostring ("S"); this method is converted to ISO 8601 standard string format.
This article is copyrighted by it.com (www.xueit.com). This statement must be reprinted by any organization or individual.ArticleThe original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.
recently used ASP. net + SQLite database to develop a website program, the results encountered a headache in date Processing:
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
exception details: system. formatexception: the string is not recognized as a valid datetime.
Solution:
Converts a type when the date is saved to the SQLite database, for example, string _ now = system. datetime. Now. tostring ("S ");
That is to say, adding s to the. tostring () method solves the problem of date reading errors.
Simple code example:
String _ indate = request ["indate"]; // The input date, for example, 2009-2-21
Datetime _ intime = convert. todatetime (_ indate );
// The SQL statement for saving data is as follows:
Insert into table (indate) values ('"+ _ intime. tostring (" S ") +"'); // convert
Because ISO 8601 Description: (http://msdn.microsoft.com/zh-cn/library/ms187819.aspx)
A string example is provided:
* 2004-05-23t14: 25: 10
* 2004-05-23t14: 25: 10.487
Therefore, the date saved by SQLite must be converted to ISO 8601 standard string format.
Use date. tostring ("S"); this method is converted to ISO 8601 standard string format.
This article is copyrighted by it.com (www.xueit.com). This statement must be retained by any organization or individual and the original article is clearly displayed on the article page. Otherwise, the legal liability will be held accountable.