sql CE中的日期问题 [英] problem with date in sql CE

查看:32
本文介绍了sql CE中的日期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 sqlCE 数据库,我有 Tdate 字段(日期时间)

i have sqlCE DataBase, i have Tdate field (datetime)

我注意到他的格式是:MM/DD/YYYY

i notice that his format is: MM/DD/YYYY

在我的 C# 程序中,我使用的日期格式为:DD/MM/YYYY.

in my C# program i work with date in: DD/MM/YYYY format.

如何将我的 C# 格式插入到我的 sqlCE 数据库中?

how i can insert to my sqlCE data base my C# format ?

推荐答案

我注意到了 Tdate 字段(日期时间)他的格式是:MM/DD/YYYY

i have Tdate field (datetime) i notice that his format is: MM/DD/YYYY

不,日期时间字段没有任何格式.格式是在从数据库中读取日期时间值转换为字符串时确定的.

No, the datetime field doesn't have any format. The format is determined when the datetime value is converted into a string after reading it from the database.

在数据库中插入日期时间值时同样有效,您使用的是日期时间值,而不是字符串.如果您向数据库提供字符串值,它将尝试将其解析为日期时间值.无论您在插入日期时间值时使用何种格式,都不会影响读取时返回值的方式,因为只有值存储在数据库中,而不是格式.

The same works when you insert a datetime value in the database, you use a datetime value, not a string. If you supply a string value to the database, it will try to parse it into a datetime value. Whatever format you use when you insert the datetime value, that doesn't affect how the value is returned when you read it, as only the value is stored in the database not the format.

当您插入值时,您应该使用参数化查询,以便将日期作为 DateTime 值提供,而不是作为查询中的格式化字符串.

When you insert the value you should use a parametererized query so that you supply the date as a DateTime value, not as a formatted string in the query.

当您从数据库中读取数据时,您会获得一个 DateTime 值.您可以设置应用程序的区域性以控制如何完成从 DateTime 到字符串的默认转换,或者在转换时使用特定的区域性或格式.

When you read the data from the database, you get a DateTime value. You can either set the culture of the application to control how the default conversion from DateTime to string is done, or use a specific culture or format when you convert it.

这篇关于sql CE中的日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆