Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12376111
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2014-03-11 20:44:26

    win8系统,特别是一个英文或俄文的系统中,它们的日期形式往往是不同的。中文的系统的日期形式常常是 年-月-日 时:分:秒;而其它的系统就有些区别。

    当我们的数据库中使用到Datetime这样的字段时就需要特别注意了。往往因为时间格式的不对,你往往数据库里面写或者读数据的时候都会报一些错。

image

图1

image

图2

    默认情况下,但DateTime这样的字段写个0给它会报一些错误的。为了避免这些问题,每个使用到时间的工程的App.config文件中应该这样写:


  1. <connectionStrings>
  2. <add
  3. name="mySqlCon" connectionString="Server=localhost;Port=3306;Database=mydb;charset=gb2312;Uid=root;Pwd=;
  4. allow user variables=true;
  5. Allow Zero Datetime=true;" providerName="MySql.Data.MySqlClient"/>
  6.   </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

阅读(3773) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~