我在运行模式下插入日期的日期未插入到数据库中 [英] what i insert the date in the run mode that date is not inserted in to the database

查看:88
本文介绍了我在运行模式下插入日期的日期未插入到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以下字段



fromdate calendarimage





Todate calendarimage



哪个日期我选择在fromdate和todate中显示的日期。但是在数据库日期中存储的格式为1/1/1900 12: 00:00 AM。



为什么?



fromdate和todate数据类型是数据库中的datetime。 br />


当我插入此查询的日期时如下



SqlCommand cmd = new SqlCommand(insert into BirthDayWish值(''+ txt_name.Text +'',''+ FromDate.SelectedDateValue.ToString()+'',''+ txt_mobile.Text +'',''+ Todate.SelectedDateValue .ToString()+'',''a'',''+ txt_Email.Text +''),con);



请帮忙我。

i have to fields as follows

fromdate calendarimage


Todate calendarimage

which date i choose that date displayed both in the fromdate and todate.but in the database date stored in the format as 1/1/1900 12:00:00 AM.

why?

fromdate and todate datatype is datetime in the database.

when i insert the date for this query as follows

SqlCommand cmd = new SqlCommand("insert into BirthDayWish values(''" + txt_name.Text + "'',''" + FromDate.SelectedDateValue.ToString() + "'',''" + txt_mobile.Text + "'',''" + Todate.SelectedDateValue.ToString() + "'',''a'',''" + txt_Email.Text + "'')", con);

please help me.

推荐答案

FromDate.SelectedDateValue.ToString() ToDate的内容.SelectedDate Value.ToString()未被识别为有效日期或为空。



调试并检查它们的值。



尝试在sql周围放置一些条件语句,以确认你有有效的数据,例如:使用 DateTime.TryParse



最后,当使用日期和数据库时,明确且不明确地始终是个好主意关于日期格式,请尝试使用 FromDate.SelectedDateValue.ToString (dd-MMM-yyyy)
The contents of FromDate.SelectedDateValue.ToString() and ToDate.SelectedDateValue.ToString() are not being recognised as valid dates or are null.

Debug and check their values.

Try putting some conditional statement around the sql to confirm you have valid data e.g. using DateTime.TryParse

Finally when using dates and databases it is always a good idea to be explicit and unambigous about date formats so try using FromDate.SelectedDateValue.ToString("dd-MMM-yyyy")


这篇关于我在运行模式下插入日期的日期未插入到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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