在SQL Server datetime字段中格式化日期时间的正确方法是什么? [英] what is the correct way to format a datetime in SQL server datetime field

查看:333
本文介绍了在SQL Server datetime字段中格式化日期时间的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个dateTime对象,我想在SQL Server datetime字段中插入。这样做的正确格式是什么?

解决方案

正确的方法是使用参数化查询, 文字格式。然后,您只需使用强类型的 SqlDbType.DateTime 参数。



(如果您绝对必须使用文本格式来执行此操作 - 我强烈推荐反对它 - 然后像 yyyyMMdd HH:mm:ss 应该做的技巧。)


I have a dateTime object in C# and i want to do an insert into SQL Server datetime field. What is the correct format for this?

解决方案

The correct way to do this is by using a parameterised query, not text formatting. Then you can just use a strongly-typed SqlDbType.DateTime parameter.

(If you absolutely must use text formatting to do this - and I strongly recommend against it - then something like yyyyMMdd HH:mm:ss should do the trick.)

这篇关于在SQL Server datetime字段中格式化日期时间的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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