开发者

cant insert date to mysql DB from c#

开发者 https://www.devze.com 2023-03-29 13:52 出处:网络
I\'m using c sharp and mysql. when i\'m trying to insert a date from DateTime type to date colum开发者_StackOverflow社区n in DB all i get is 0000-00-00

I'm using c sharp and mysql. when i'm trying to insert a date from DateTime type to date colum开发者_StackOverflow社区n in DB all i get is 0000-00-00

i'm parsing my DateTime like this : sessionDate.ToShortDateString()

but getting empty date ...

any help please


MySql uses date in yyyy-MM-dd format,So U can overide the toString() method Of DateTime.Now property.

YourDate= DateTime.Now.ToString("yyyy-MM-dd");


Try this to format your date time to a string value that is acceptable to MySQL

String.Format("{0:yyyy-MM-dd}", sessionDate);

0

精彩评论

暂无评论...
验证码 换一张
取 消