从C#在sql中保存日期的问题 [英] problem in saving date in sql from c#
本文介绍了从C#在sql中保存日期的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,iam yogesh和我在sql表中保存日期时遇到问题
我保存日期的代码是
Hi iam yogesh and i m having problems in date saving in sql table
my code for saving a date is
datetime mdat;
mdat = dtpdate.Value; //dtpdate is datepicker
insert into saltrn (dat) values(mdat.ToString("dd/MM/yyyy"))
//for eg: when i saved 27-11-2011 in my table(.entry is saved)..... Now when i am //looking from sql select query, the same entry
// looks like 1894-07-16 00:00:00.000
//why is it happening?
请帮帮我..而不是27-11-2011,1894-07-16 00:00:00.000将被保存.
HELP ME PLEASE .. instead of 27-11-2011, 1894-07-16 00:00:00.000 is getting saved.
推荐答案
如果您使用的是DateTime在SQL表中输入,要传递的正确字符串格式为:YYYY-MM-DD,所以在您的情况下为2011-11-27.
If you are using a DateTime type in the SQL table, the proper string format to pass would be: YYYY-MM-DD, so 2011-11-27 in your case.
这篇关于从C#在sql中保存日期的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文