如何将datepicker转换为tostring [英] How do I convert datepicker to tostring

查看:70
本文介绍了如何将datepicker转换为tostring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmd.Parameters.AddWithValue("@dob", DatePicker1.CalendarDate);







我尝试了什么:



cmd.Parameters.AddWithValue(@ dob,DatePicker1.CalendarDate);




What I have tried:

cmd.Parameters.AddWithValue("@dob", DatePicker1.CalendarDate);

推荐答案

不要:将其作为DateTime值直接传递给SQL:

Don't: pass it directly to SQL as a DateTime value:
cmd.Parameters.AddWithValue("@dob", DatePicker1.Value);



那样,你可以减少任何问题两个系统之间的字符串到日期转换可能会以不同的方式解释日期:2004年3月2日02-03-04,20014年2月3日或2002年3月4日?


如果您想要一个字符串,因为您将其作为字符串存储在SQL中,那么请更改您的数据库并将其存储为DATE或DATETIME列。将日期存储为字符串会在以后提供真正令人讨厌的问题并且效率更高 - 始终以最合适的格式存储数据,而不是今天最简单的代码。


That way, you reduce any problems with "string-to-date" conversions between two systems that may interpret dates differently: is 02-03-04 the 2nd March 2004, the 3rd February 20014, or 4th March 2002?

And if you want a string because you are storing it as a string in SQL, then change your DB and store it as a DATE or DATETIME column instead. Storing dates as strings gives really nasty problems later on as well as being more efficient - always store data in the most appropriate format, not the simplest for your code today.


这篇关于如何将datepicker转换为tostring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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