win8系统,特别是一个英文或俄文的系统中,它们的日期形式往往是不同的。中文的系统的日期形式常常是 年-月-日 时:分:秒;而其它的系统就有些区别。
当我们的数据库中使用到Datetime这样的字段时就需要特别注意了。往往因为时间格式的不对,你往往数据库里面写或者读数据的时候都会报一些错。
图1
图2
默认情况下,但DateTime这样的字段写个0给它会报一些错误的。为了避免这些问题,每个使用到时间的工程的App.config文件中应该这样写:
- connectionStrings>
- add
- name="mySqlCon" connectionString="Server=localhost;Port=3306;Database=mydb;charset=gb2312;Uid=root;Pwd=;
- allow user variables=true;
- Allow Zero Datetime=true;" providerName="MySql.Data.MySqlClient"/>
- /connectionStrings>
Allow Zero Datetime=true; is very important set here.
而当我们从数据库中读出一些日期数据时,则应该它将强制轮换成我们所需要的数据。
And when get the DateTime variable from mysql db, force to conver it to string like this:
String str1 = Convert.ToString(db.data);
参考文献:
The relate blogs:
http://www.cnblogs.com/linn/archive/2009/08/31/1557355.html
http://hi.baidu.com/hailwater/item/62c9921c1b1ddffa64eabfe0
http://zhidao.baidu.com/link?url=TnBewdfU4j301A6FYDdVZM04xmUV5RVQR3CJMq2HXmR9DWfHxnyK_AwcXPuHu-RO608PHMjJ1Aa4IjZ29nK_8_